Code to tell if a query name exists? (1 Viewer)

Takashi

New member
Local time
Today, 09:11
Joined
Jan 19, 2001
Messages
9
I need to write a routine that can tell if a query with a specified name already exists. I've already created something that's functional, albiet very crude. Can anyone show me the better way to do this? (I know there must be one)

Here's what I'm using now:

Query_Name = "XAQ_" & Forms![dave_module_test]![CMB_College] & "_DA_Query"

On Error GoTo Create_Error

If IsNull(DB.QueryDefs(Query_Name)) = False Then Debug.Print "Result of " & Query_Name & " Query: Exists"
Debug.Print "Result of " & Query_Name & " Query: Exists."

--query stuff here--

Create_Error:

--query doesn't exist--
 

ntp

Registered User.
Local time
Today, 09:11
Joined
Jan 7, 2001
Messages
74
Use this function

Public QueryExists(strQryName as String) as Boolean
Dim qdf as QueryDef
Dim boolExists as Boolean
boolExists = False
For each qdf In currentdb.queryDefs
If qdf.Name = strQryName then
QueryExists = True
Exit Function
End if
Next qdf
QueryExists = boolExists
End Function

ntp
 

Users who are viewing this thread

Top Bottom