Hi,
I have about 40 Queries by Year. I don't want to write it down one
by one to make a command button.
DoCmd.OpenQuery "2007", acViewNormal, acEdit
DoCmd.OpenQuery "20071", acViewNormal, acEdit
DoCmd.OpenQuery "20072", acViewNormal, acEdit
I'm tired if I make the change then I have to go back the command
button to adjust the name of the queries.
Is there a way for create a code for "Like 2007*" or Like 2006* or
Like 2005* or Like 2004*, etc. in one command button.
DoCmd.OpenQuery "2007", acViewNormal, acEdit
DoCmd.OpenQuery "2006", acViewNormal, acEdit
DoCmd.OpenQuery "2005", acViewNormal, acEdit
DoCmd.OpenQuery "2004", acViewNormal, acEdit
Your help would be much appreciated.
Thanks
Douglas J. Steele - 31 Mar 2007 12:45 GMT
No, there's no way to have the OpenQuery command do that, but you could easy
run a loop in VBA to go through all the queries and only run those that
match a certain criteria:
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Set dbCurr = CurrentDb()
For Each qdfCurr In dbCurr.QueryDefs
If Left$(qdfCurr.Name, 4) = "2007" Then
DoCmd.OpenQuery qdfCurr.Name, acViewNormal, acEdit
End If
Next qdfCurr
For the life of me, though, I don't understand why you'd want to do that:
queries aren't intended to be interacted with.

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
> Hi,
>
[quoted text clipped - 19 lines]
>
> Thanks