Querydefs

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top