Checking if a Query already exists in Access
Checking if a Query already exists in Access
(OP)
I am having a bit of a problem with VB in Access, I can not find any methods to say whether a particular query already exits. There used to be an IfExists method which does not seem to be supported. Does anyone know how I could achieve this?
RE: Checking if a Query already exists in 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