Querydefs

G

Guest

How do I check for the existence of a named query before deleting it? eg using:

db.QueryDefs.Delete "qryPromotionText"

My procedure needs to delete the query before re-generating it with new SQL,
but if it isn't there I get an error. I did have an error trap but the same
error number (3265) is used for other errors so I'm looking for an
alternative.

Any ideas?
Rick
 
J

John Spencer

Try the following code

Public Function DoesQueryExist(strQueryName As String) As Boolean
' Access 2000 and later
On Error Resume Next
DoesQueryExist = IsObject(CurrentDb.QueryDefs(strQueryName))

End Function

Although if the query already exists there is really no need to delete it,
all you really need to do is to replace its SQL property with the new sql
statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top