?
Solved

Table existence

Posted on 2003-03-28
4
Medium Priority
?
169 Views
Last Modified: 2010-05-01
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.
0
Comment
Question by:countyworker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
SSSoftware earned 80 total points
ID: 8228779
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
0
 
LVL 4

Expert Comment

by:SSSoftware
ID: 8228780
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
0
 

Expert Comment

by:CleanupPing
ID: 8531383
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.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440760
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question