I am assuming that the table with all of hte query names and group_ids in it
is complete. I am going to name this table query_list with fields group_id
and queryname in my example
Sub RunQueries(GroupID As Long)
Dim strQuery As String
Dim qry As QueryDef
Dim rec As Recordset
'get a list of all queries for the given groupid
strQuery = "Select * from [query_list] where group_id=" & GroupID
Set qry = CurrentDb.CreateProperty("", strQuery)
Set rec = qry.OpenRecordset()
'record list of all of the queries
With rec
'go through the list until it is complete
If Not (.EOF) Then
'grab the appropriate query with name of in the QueryName field
Set qry = CurrentDb.QueryDefs(.Fields("QueryName"))
'run the query
qry.Execute
'move to the next query
.MoveNext
End If
End With
'clean up by setting objects to nothing
Set qry = Nothing
Set rec = Nothing
End Sub
Please let me know if this is helpful and if I can provide more assistance.
DavPet said:
I have a lot of queires.
I want to put the query names in a table, one field of the table will have a
group_id. Then I want to execute the queries for a certain group_id.
Please jump start me on how to do it.