Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
For Each obj In dbs.AllQueries
If obj.Name = "QryWhatEver" Then
Debug.Print obj.Name
End If
Next obj
Dim dbs As DAO.Database
Dim Rst As DAO.Recordset
dim MyQueryName as String
Set dbs = CurrentDb()
Dim QDF As DAO.QueryDef
Dim PRM As Parameter
MyQueryName="thenameof thequery"
on error goto NoQuery:
Set QDF = dbs.QueryDefs(MyQueryName)
For Each PRM In QDF.Parameters
PRM.Value = Eval(PRM.name)
Next PRM
Set Rst = QDF.OpenRecordset(dbOpenDynaset)
With Rst
If Rst.BOF And Rst.EOF Then
'the query exists but has no records
Rst.Close
Set Rst = Nothing
Set dbs = Nothing
Else:
'if you want to do anything do it here
End If
End With
Rst.Close
ExitHere
Set Rst = Nothing
Set dbs = Nothing
ExitSub
NoQuery:
if err.number=7874 then
msgbox "Cant Find Query"
resume ExitHere: