我是VBA的新手,所以我很难理解发生了什么。我正在尝试使用以下代码填充具有50,000条记录的表:
Sub arrayData()
Dim custnames() As Variant
Dim num As Long, dbs As Database, InsertRecord As String
Dim CusSalaryId As Long, num1 As Long, EmpId As Long
Dim EmpSalary As String
Set dbs = CurrentDb()
EmpId = 0
CustSalaryId = 0
For num1 = 0 To 50000
CustSalaryId = CustSalaryId + 1
EmpId = EmpId + 1
custnames = Array("$1000", "$500", "$300", "$600")
num = Int((UBound(custnames) - LBound(custnames) + 1) * Rnd + LBound(custnames))
EmpSalary= custnames(num)
InsertRecord = "insert into SALARY (SalaryID, NetSalary, EmployeeID)
values (" & "'" & CustSalaryId & "'" & "," & "'" & EmpSalary & "'" & "," & "'" & EmpId & "'" & ")"
dbs.Execute InsertRecord
Debug.Print SalaryId; EmpSalary; EmpId;
Next
End Sub
运行它时,我仅获得2条记录: Salary Table Output
答案 0 :(得分:0)
我已经弄清楚了,很抱歉浪费您的时间!这是因为我作为薪水表创建的关系被链接到只有2条记录的雇员表,因此薪水表最多只能创建2条记录。再次抱歉,您在发布之前没有仔细检查所有内容。