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

How can I tell if a certain table exists in a Database?

Status
Not open for further replies.
Aug 9, 2001
23
0
0
GB
On the On_Open event of a form I want to know if a certain table exists in the Database...Any ideas?

Thom.
 
Let Access test for you, for example:

Sub ToOpenTable()
On error goto ErrHandler
DoCmd.OpenTable "TableName", acViewPreview


ExitHere:
Exit Sub

ErrHandler:
If err.number = 7874
Table does not exist
Do Something
Resume exit here

mac



 
Hallo,

This code I wrote checks for a query, but you could easily adapt it:
Function ysnQueryExists(ByVal pstrQueryName As String) As Boolean
On Error GoTo Err_ysnQueryExists
' Comments : Determines if the named query exists
' Parameters: pstrQueryName - name of query to check
' Returns : True if named query exists, false otherwise
' : also returns false if pstrQueryName is an empty string
'
If Len(pstrQueryName) = 0 Then GoTo Err_ysnQueryExists
If Len(CurrentDb.QueryDefs(pstrQueryName).name) = 0 Then GoTo Err_ysnQueryExists
ysnQueryExists = True
Exit_ysnQueryExists:
Exit Function
Err_ysnQueryExists:
ysnQueryExists = False
Resume Exit_ysnQueryExists
End Function

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top