Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a Query already exists in Access

Status
Not open for further replies.

wowski

Electrical
Jan 22, 2001
27
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?
 
Replies continue below

Recommended for you

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor