OpenQuery Code

A

Anthony Viscomi

Hi All:

I have multiple queries that I would like to run via VBA code; I know how to
use the DoCmd.OpenQuery "qry_Mktbl_Update_CCE_CF_UNITS"
DoCmd.OpenQuery "qry_Mktbl_Update_CCE_U3M_UNITS"
DoCmd.OpenQuery "qry_Mktbl_Update_CCE_U5M_UNITS"

Etc...

My question is:
Can I use a wildcard to run these queries? In other woulds all of the
queries that I want to run start with, qry_Mktbl and there are a lot of
them. Thus, maybe I could use something like this:
DoCmd.OpenQuery "qry_Mktbl_"*; which doesn't work.

Thanks in advance!
Anthony Viscomi
 
D

Douglas J. Steele

Try something like the following:

Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef

Set dbCurr = CurrentDb()
For Each qdfCurr In dbCurr.QueryDefs
If InStr(qdfCurr.Name, "qry_Mktbl_") = 1 Then
DoCmd.OpenQuery qdfCurr.Name
End If
Next qdfCurr
 
A

Anthony Viscomi

Thanks! its just what I needed!
Douglas J. Steele said:
Try something like the following:

Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef

Set dbCurr = CurrentDb()
For Each qdfCurr In dbCurr.QueryDefs
If InStr(qdfCurr.Name, "qry_Mktbl_") = 1 Then
DoCmd.OpenQuery qdfCurr.Name
End If
Next qdfCurr


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


how
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top