troubleshooting Question

INSERT Statement using VBA in Access Database

Avatar of mickygene
mickygene asked on
Microsoft Access
7 Comments5 Solutions5085 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 5 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 5 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros