open multiple queries

Batten

New member
Local time
Today, 17:37
Joined
Aug 7, 2008
Messages
7
A quick question

I have 24 queries and all of them starts with qrySel and then a person's name. Currently I have 24 "Openquery" commands in VBA to open the queries refresh them and close them.

Is there a way that I can do this with one simple code and not 24 docmds?

Thanks
 
Create an array and populate the array with the names then loop through the array

Dim Names(23)

Names(0) = "Tom"
Names(1) = "Dick"
Names(2) = "Harry"
etc

For X = 0 To 23
DoCmd.OpenQuery "qrySel" & Names(X)
Next

Alternatively create a table with the names in and loop through the table. This is more flexible as you can add names to list without recording vba

David
 
Refresh them?? What do you mean by this??

You can do something like...
Code:
dim qry as object
For each qry in currentdb.querydefs
    if qry.name like "qrySel*" then
        do something
    endif
next
Or you can make a table with the query names, open and read the table to execute your code...

Greets from Amsterdam
 

Users who are viewing this thread

Back
Top Bottom