Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • 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
Joined
Jan 22, 2001
Messages
27
Location
AU
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?
 
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

Back
Top