I wrote the following subroutine for you in the Northwind database which comes with Access.
Sub FindQuery()
Dim QuerySought As QueryDef
'QueryName = "XYZ"
QueryName = "Sales By Year"
On Error GoTo NotFound
Set QuerySought = CurrentDb.QueryDefs(QueryName)
MsgBox ("Query " + QueryName + " found in database"

'Other statements
Exit Sub
NotFound:
MsgBox ("Query " + QueryName + "not found in database"

'Other statements
End Sub
Notice the statements
'QueryName = "XYZ"
QueryName = "Sales By Year"
If u wish to check for the name "XYZ" REM the 'Sales by Year' statement and vice versa
In Northwind the procedure will report "XYZ" as missing and "Sales By Year" as found.
Good luck!
Mala