Check Query Exists?

icezebra

Registered User.
Local time
Today, 21:20
Joined
Feb 12, 2007
Messages
22
How would I check programmatically that a querydef already exists.

I.e. something along these lines:
Code:
If Db.QueryDefs(strQueryDef).Exist = False Then

        Set QD = Db.CreateQueryDef(strQueryDef, strSQL)

Else

..... and so on.

It's the If line I'm interested in. strQueryDef is a string variable which contains the name of the relevant query.

Help!
 
You need a For....Each loop to loop through the QueryDef collection checking the name of each querydef


for each qryDef in currentdb.querydefs
if qryDef.name=NameVariable then
exists
end if
next qryDef
 
Top stuff. That solves my problem perfectly!
 
How would I do the same for a form?

For Each Form in CurrentDB
If...

Doesn't work.


Arrg. :D
 
Something like below

Dim frm As Object

For Each frm In CurrentProject.AllForms
MsgBox frm.Name
Next frm
 

Users who are viewing this thread

Back
Top Bottom