Running queries multiple times in VBA

Richhol65

Registered User.
Local time
Today, 19:27
Joined
Aug 24, 2013
Messages
43
Hi there

Hopefully someone can help me.

I have a situation where I am using a maketable query to create a table and then I need to use append queries to then add additional records to the created table - some of these are just run once and some multiple times.

if possible, I do not want to hard code the query multiple times i.e.

Code:
DoCmd.OpenQuery "qryCreate_1"
DoCmd.OpenQuery "qryAppend_1"
DoCmd.OpenQuery "qryAppend_1"
DoCmd.OpenQuery "qryAppend_1"
etc

So is there a way I can run the make table query and then get some sort of loop to run the append query a number of times ?

Thanks in advance

Rich
 
standaard loop goes something like
Code:
dim I as integer
For I =1  to 10
   ' do something 10 times
next I

Does that help you?

** Going to omit questions about your requirement or data design
 
How do you define the number of times this query is to be run?
 
If you know beforehand how many times you want it to run or if this can be calculated, you can use a simple For Loop with a variable as the loop counter

Code:
Dim i as Integer 
i = hard coded number or calculated value
 
DoCmd.OpenQuery "qryCreate_1"
For i = 1 to 3
    DoCmd.OpenQuery "qryAppend_1"
Next i
 
All

Sorry for such a silly question - I have similar loops already in the code but for other areas and my thoughts just hadn't put 2 and 2 together at all

Thanks all

Rich
 

Users who are viewing this thread

Back
Top Bottom