Article ID: 210598 - View products that this article applies to.
This article was previously published under Q210598
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.mdb).
This article shows you how to create a sample user-defined function to check whether an object exists in the current database. This can be useful before you create a new object (such as a table, a form, or a report) in the database.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
How to Create the FunctionCheck for the existence of an object in the current database by using the ObjectType argument to determine the type of object to be retrieved (tables, queries, forms, reports, macros, and modules) and the ObjectName argument to represent the name of the specified object type.
The function will return:
True (-1), if the object exists.CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
False (0), if the object does not exist.
To create the function follow these steps:
How to Use the Function