Running queries multiple times in VBA (1 Viewer)

Richhol65

Registered User.
Local time
Today, 00:22
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
 

namliam

The Mailman - AWF VIP
Local time
Today, 01:22
Joined
Aug 11, 2003
Messages
11,695
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
 

pr2-eugin

Super Moderator
Local time
Today, 00:22
Joined
Nov 30, 2011
Messages
8,494
How do you define the number of times this query is to be run?
 

DavidAtWork

Registered User.
Local time
Today, 00:22
Joined
Oct 25, 2011
Messages
699
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
 

Richhol65

Registered User.
Local time
Today, 00:22
Joined
Aug 24, 2013
Messages
43
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

Top Bottom