Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004

    Unanswered: Check to see if query exists

    Is there a function I could use with VBA to check to see if a query exists? Thanks in advance.

  2. #2
    Join Date
    Jun 2004
    Never mind

    Function objectExists(strObjectName As String) As Boolean
    Dim qry As QueryDef

    Dim db As Database
    Set db = CurrentDb()

    For Each qry In db.QueryDefs
    If = strObjectName Then
    objectExists = True

    Exit Function
    End If
    Next qry

    End Function

  3. #3
    Join Date
    Oct 2003
    Another way to do it is to use an on error goto block. You proceed as though an error would not occur, but if the query does not exist an exception will be raised and you will "catch" it. Test to be sure that the error-code is what you expected it to be ("query not found"), and if not, process it as a real error.

    This is an efficient technique when you "expect" that the query will exist most of the time. Given that Access is going to search for the query anyway, it treats the exceptional case ("huh? it's not here?") as an exception.

    Now, it's really up to you how you choose to do it.
    ChimneySweep(R): fast, automatic
    table repair at a click of the

Posting Permissions

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