Originally Posted by
June7
I didn't mention any code earlier. Don't know what you are asking for.
I thought that the question might be for me, but didn't want to jump in because it was directed to you. The following should iterate over the stored queries and report the names and types that begin with _
NOTE: any character might be useful - except ~
LIST OF QUERY TYPE CONSTANTS HERE
This first code example is so you can identify the types you need to run and edit the Select Case block accordingly, using the type name constants.
Code:
Sub LoopQueries()
Dim qdf As DAO.QueryDef
For Each qdf In CurrentDb.QueryDefs
If Left(qdf.Name, 1) = "_" Then
Debug.Print qdf.Name & " " & qdf.Type
End If
Next
End Sub
While the following code will run Select queries, I have no idea if that's useful. I doubt it, but it's there anyway as part of the example. I'm also assuming that if there's a failure for any one query, code should report that failure and then stop. Any query that has parameters (such as a form reference) will fail if that form isn't open. Likely also will fail if a stacked query (one that calls other queries) has such parameters.
Code:
Sub RunQueries()
Dim qdf As DAO.QueryDef
On Error GoTo errHandler
For Each qdf In CurrentDb.QueryDefs
If Left(qdf.Name, 1) = "_" Then
Select Case qdf.Type
Case dbQDelete, dbQAppend, dbQUpdate
CurrentDb.Execute qdf.Name, dbFailOnError
Case dbQSelect, dbQSetOperation
DoCmd.OpenQuery qdf.Name
End Select
End If
Next
exitHere:
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "ERROR IN " & qdf.Name
Resume exitHere
End Sub
Then there is the method I mentioned of calling queries listed in a table, but this isn't it.