Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Posts
    6

    Unanswered: How to tell if a QueryDef exist on the Access DB ?

    Hi I have this code to delete an existing querydef on the Access 97 DB:

    db.QueryDefs.Delete "qry_ABC"

    but I get an error if the querydef wasn't already there.

    So how can I check if it exist then delete ?

    Thanks
    Matt

  2. #2
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    You don't need to check if it exists. Just add
    On Error Resume Next
    in front of your
    db.QueryDefs.Delete "qry_ABC"

    and it will not halt on error if query is not found.

    Or try this:

    For Each qdf in db.QueryDefs
    If qdf.Name = "qry_ABC" Then
    db.QueryDefs.Delete "qry_ABC"
    Exit For
    End If
    Next

    This will search all querydefs and if a match is found, it will try to delete it. However, if the query is open, you can't delete it and you'll have to handle the error.

    Regards,

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •