My code below - looks for the prefix "Crash" and runs any query that contains "Crash" in the name.
This then runs 13 queries - so i am just looking for a way to close the queries down that are blank, and just leave the ones that i need to look into further.
Any thoughts.
This then runs 13 queries - so i am just looking for a way to close the queries down that are blank, and just leave the ones that i need to look into further.
Any thoughts.
Code:
Function Test_it()
Dim strPrefix As String
strPrefix = "Crash"
Run_Queries (strPrefix)
End Function
Function Run_Queries(strPrefix As String) As Integer
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strQryName As String
Dim iQryCt As Integer
Dim iQryRan As Integer
Dim i As Integer
Set dbs = CurrentDb
iQryCt = dbs.QueryDefs.Count
i = Len(strPrefix)
iQryRan = 0
For Each qdf In dbs.QueryDefs
strQryName = qdf.Name
Debug.Print strQryName
If LCase(Left(strQryName, i)) = LCase(strPrefix) Then
Debug.Print " ** Run: " & strQryName & vbTab & qdf.Type
If qdf.Type = 0 Then ' Select query
' Open this query to view results
DoCmd.OpenQuery strQryName
'ExportQuery strQryName, "SELECT * FROM strQryName;", , , Environ("Temp") & "\"
ElseIf qdf.Type = 48 Then ' Update query
dbs.Execute strQryName
End If
iQryRan = iQryRan + 1
Else
End If
Next qdf
Set qdf = Nothing
Set dbs = Nothing
Run_Queries = iQryRan
End Function