Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop Through Queries with a Name Like a Sample

Tags:

vba

ms-access

I have a lot of queries that I would like to run, and they all have the same ending in their name. So, instead of listing tens and tens of queries into DoCmd, is there a way to tell the DoCmd to open all queries that have the same string of letters in their name?

For example, qry1ABC and qry2ABC

Run all queries with a name like "ABC"

like image 453
veckorevyn Avatar asked Feb 17 '26 12:02

veckorevyn


1 Answers

This loops through all the queries in the DB and runs only the ones starting with which with a name like ABC:

Public Sub TestMe()

    Dim db As DAO.Database
    Set db = CurrentDb

    Dim qdf As DAO.QueryDef

    For Each qdf In db.QueryDefs
        Debug.Print qdf.Name
        If qdf.Name Like "*ABC*" Then
            DoCmd.OpenQuery qdf.Name
        End If
    Next qdf

End Sub
like image 145
Vityata Avatar answered Feb 20 '26 03:02

Vityata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!