I am trying to insert a bunch of dummy records into an Access Database table using VBA in a module called survey_results. Below is the code I am using. I'm getting the infamous Object variable or With block variable not set (Error 91). I have Access 2003 using windows xp.
Public Sub build_survey()
'Option Compare Database
Dim random_number As Integer
Dim dbs As DAO.Database
Dim upperbound As Integer
Dim lowerbound As Integer
Dim i As Integer
Dim j As Integer
Dim k as Integer
lowerbound = 1
upperbound = 5
For i = 1 To 666 'Number of Classes
For j = 1 To 500 'Number of Students answering the survey
For k = 1 To 10 'Number of Question
'random_number = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
random_number = Int((5 * Rnd) + 1) 'Values can be from 1 to 5
dbs.Execute "INSERT INTO survey_results (class_id, student_id, question_id, value_id) VALUES (i,j,k,random_number)"
Next
Next
Next
End Sub
Start Free Trial