Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Access Other topics FAQ

Access Howto:

How can I test to see if an object Exists in the database by jimmythegeek
Posted: 26 May 00 (Edited 27 Sep 07)

This is an awsome function to determine if any object (table, query, form, report, macro, or module) exists in a database. The IsLoaded function tells you if a form is open, but this function tells you if an object EXISTS.

It is extremely simple to use: Just copy the function into a module and your ready to go.

The function returns a true or false whether the object that you passed exists or not. To use it, Simply pass it what type of object, using the Access intrinsic constants (acTable, acQuery, acForm, acReport, acMacro, acModule) and the string name of the object, for example:

If ObjectExists(acTable, "tblOrders") Then .....     OR

If ObjectExists(acQuery, "CashLtrRpt") Then DoCmd.DeleteObject acQuery, "CashLtrRpt"

That's it! I hope you enjoy it, I have used it hundreds of times. I wrote it when I could not find anything similar looking in every resource I could find. Let me know if it helps you.

Jim Lunde


Function ObjectExists(ObjType As Integer, ObjName As String) As Boolean
    'Purpose: Determines whether or not a given object exists in database
    'Example: If ObjectExists(acTable, "tblOrders") then ...

On Error Resume Next
    Dim strTemp As String, strContainer As String
    Select Case ObjType
        Case acTable
            strTemp = CurrentDB.TableDefs(ObjName).NAME
        Case acQuery
            strTemp = CurrentDB.QueryDefs(ObjName).NAME
        Case acMacro, acModule, acForm, acReport
            Select Case ObjType
                Case acMacro
                    strContainer = "Scripts"
                Case acModule
                    strContainer = "Modules"
                Case acForm
                    strContainer = "Forms"
                Case acReport
                    strContainer = "Reports"
            End Select
        strTemp = CurrentDB.Containers(strContainer).Documents(ObjName).NAME
    End Select
    ObjectExists = (Err.Number = 0)
End Function

Back to Microsoft: Access Other topics FAQ Index
Back to Microsoft: Access Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close