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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting

Status
Not open for further replies.

EscapeUK

Programmer
Jul 7, 2000
438
GB
How do I in code

delete a query called qry1
delete another query called qry2
delete yet another query called qry3

However is is possible that they might not exist.

so what i need to do is search for the qry if it exists delete it if not do nothing

ta
 
You can do in only in VB.
docmd.DeleteObject acQuery,"queryName" John Fill
ivfmd@mail.md
 
In addition to using DeleteObject, you'll need to use error handling to trap the error that occurs if the query doesn't exist.

If you prefer to verify that the query exists first, use code like this:
Code:
Sub DeleteQuery(QueryName As String)
    Dim db As DAO.Database, qdf As DAO.QueryDef
    Set db = CurrentDb()
    For Each qdf In db.QueryDefs
        If qdf.Name = QueryName Then
            Set qdf = Nothing
            DoCmd.DeleteObject acQuery, QueryName
            Exit For
        End If
    Next qdf
    Set qdf = Nothing
    Set db = Nothing
End Sub
Using an error handler will take less code, however. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top