I am new to VBA, so I'm having trouble understanding what is going on. I am trying to fill a table with 50,000 records with the following code:
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
When I run it, I get only 2 records: Salary Table Output
MsgBox (num1)after theForloop? - Md. Suman KabirNextso that we can see the last value only. - Md. Suman Kabir