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

Checking if a table exists with code? 2

Status
Not open for further replies.

BTilson

Programmer
Jul 14, 2004
139
0
0
US
I have a database app that runs a daily analysis on a report provided by one of our customers. The customer sends in their report in an excel sheet, which I then import into a table. Every morning I have to delete the old table and then import the new one. In similar instances in the past, I've simply put in a line of code to delete the table, but if for some reason something has gone wrong, and the table isn't there to begin with, the delete line will throw an error and stop the code. So is there any function to check if a table exists? If so, I could set it up to only run the delete line if the table did indeed exist.

Thanks!

Brooks Tilson
Database Development
Tilson Machine, Inc.
 
Try this

Sub DeleteTable()

Dim tbl As TableDef

For Each tbl In CurrentDb.TableDefs
If tbl.Name = "Table1" Then
CurrentDb.TableDefs.Delete tbl.Name
End If
Next tbl

End Sub

Andrew Chamberlain
National Grid
 
Excellent! That worked perfectly!

Thanks so much!

Brooks Tilson
Database Development
Tilson Machine, Inc.
 
How are ya BTilson . . .

Out of curiosity why not simply delete all records in the table and import into existing? . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top