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

Verify Table Exist At Runtime Using ADO 2.6

Status
Not open for further replies.

Foada

Programmer
Feb 4, 2002
1,110
US
Hi

Here is my problem. I am writing a utility that will verify that my database(Access2000) contains all the relavent tables, fields, data etc. I want to be able to check if a table exist and if it does not create it so here is what I have.

Private hDB As New ADODB.Connection

Private Sub CheckTables

On Error GoTo ErrHandler
hDB.ConnectionString = sDBConnection & App.Path & "\TestDB.mdb"
hDB.Mode = adModeReadWrite
hDB.Open

hDB.Execute ("Create Table Junk")

Exit Sub
ErrHandler:
Debug.Print Err.Description & Err.Number
End Sub

This works fine when the table doesn't exist, but if it does exist I get the error:

Table 'Junk' already exists.-2147217900

which again is fine as I could just trap the error and continue on with my business. The problem I have with this is the error code is not just specific to the 'table exists' message so I don't want to trap it that way. Is there a better way to check for the tables presents ie an SQL command that I have not thought of etc etc. Thanks in advance.

Tom Anything is possible, the problem is I only have one lifetime.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top