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

Checking to see if a table exists before calling query to drop it 1

Status
Not open for further replies.

KimmieB

Programmer
Apr 1, 2005
20
US
I am calling a query from a form that will drop a temporary working table. It re-creates it later in the process. I'd like to first check to see if the table exists to avoid the "table doesn't exist msg". Is the best way to loop through the current databases's tabledefs and check the name or is there a more elegant way?
 
Brute force method:
DoCmd.SetWarnings False
On Error Resume Next
DoCmd.RunSQL "DROP TABLE [your table name]"
On Error GoTo yourErrorHandler
DoCmd.SetWarnings True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya KimmieB . . . . .

This should work:
Code:
[blue]   Criteria = "[Name] = '" & "[purple][b]YourTableName[/b][/purple]" & "'"
   
   If Not IsNull(dlookup("[Name", "MSysObjects", Criteria)) Then
      [green]'Your Table Deletion Code Here[/green]
   End If[/blue]

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

Part and Inventory Search

Sponsor

Back
Top