Microsoft KB Archive/88170

{|
 * width="100%"|

INF: How to Determine If a Table or Query Exists (1.x)
'Article ID: Q88170

Creation Date: 19-AUG-1992

Revision Date: 19-SEP-1996' The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes how to determine if a query exists in a database by using Access Basic code.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the &quot;Introduction to Programming&quot; manual in Microsoft Access version 1.x.

MORE INFORMATION

Microsoft Access does not have a function to determine the existence of a specific query. Using Access Basic code, you can determine if a query exists in the database.

You can use the following sample function to return the existence of a query:

  Open the sample database NWIND.MDB and create a new module with the following function: '****************************************************************     'Declarations section of the module '****************************************************************      Option Compare Database Option Explicit '****************************************************************     ' The following function is named IsQuery. It accepts a string ' argument and returns either True(-1) or False(0). '****************************************************************      Function IsQuery (QueryName As String) As Integer Dim DB As Database Dim Snap As Snapshot Set DB = CurrentDB Set Snap = DB.ListTables Snap.MoveFirst IsQuery = False Do Until Snap.eof If Snap![Name] = QueryName And Snap![TableType] = DB_QUERYDEF Then IsQuery = True End If        Snap.MoveNext Loop Snap.Close End Function   From the View menu, choose Immediate Window. Enter the following command, and then press ENTER: "?IsQuery(&quot;Order Information&quot;)" &quot;-1&quot; should be displayed in the Immediate window (-1 represents True in Microsoft Access). Experiment by calling the function with a nonexistent query. This should display &quot;0&quot; (which represents False).

REFERENCES

For more information about testing for query or table existence in Access version 2.0 and Microsoft Access for Windows 95, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q113549 TITLE:     INF: How to Determine If a Table or Query Exists (2.0 & 7.0)
 * }

-

"THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY." '' ©1997 Microsoft Corporation. All rights reserved. Legal Notices.

''

Additional reference words: 1.00 1.10

KBCategory: kbprg kbhowto

KBSubcategory: PgmOthr