Advertisement

07.20.2007 at 08:55PM PDT, ID: 22711195
[x]
Attachment Details

INSERT Statement using VBA in Access Database

Asked by mickygene in Access Coding/Macros, Microsoft Access Database

Tags: insert, vba, access, statement, using

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
 
Loading Advertisement...
 
[+][-]07.20.2007 at 08:57PM PDT, ID: 19537164

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Coding/Macros, Microsoft Access Database
Tags: insert, vba, access, statement, using
Sign Up Now!
Solution Provided By: mbizup
Participating Experts: 5
Solution Grade: A
 
 
[+][-]07.20.2007 at 08:59PM PDT, ID: 19537167

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.20.2007 at 09:00PM PDT, ID: 19537169

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2007 at 10:32PM PDT, ID: 19537299

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.21.2007 at 03:20AM PDT, ID: 19537974

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.21.2007 at 05:06AM PDT, ID: 19538226

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.21.2007 at 09:53AM PDT, ID: 19539916

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32