Link to home
Start Free TrialLog in
Avatar of countyworker
countyworker

asked on

Table existence

Using VBA for Access, is there some way to test to see if a table exists?
If it does then continue processing, if not display a message "table not found, continuing processing on next table" and so forth.  
It's probably very simple but I'm doing this with lame books, lame F1 keys and no real support at my workplace.
Thanks for any help.
ASKER CERTIFIED SOLUTION
Avatar of SSSoftware
SSSoftware

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SSSoftware
SSSoftware

To CountyWorker:

This works:

Public Sub Tabletest()

' Prints out all table names
' Tables that begin with MSys are Access internam tables
Dim I As Integer
For I = 0 To Application.CurrentDb.TableDefs.Count - 1
    Debug.Print Application.CurrentDb.TableDefs(I).Name
Next I

' Tests for the table "TestResults"
On Error GoTo NotFound
If Application.CurrentDb.TableDefs("TestResults").Fields.Count > 0 Then
    MsgBox "Table Found"
End If
On Error GoTo 0     ' reset the error handler
Exit Sub

NotFound:
    MsgBox "Table Not found"
End Sub

Good Luck,
Ed
Hi countyworker,
This old question (QID 20566994) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept SSSoftware's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer