Code for Does Table Exist

  • Thread starter Thread starter Bradley C. Hammerstrom
  • Start date Start date
B

Bradley C. Hammerstrom

A2K

With Visual Basic code I want to test if a table exists (so I can delete
it). Something like:

IfExists "Table1" Then DoCmd.DeleteObject acTable, "Table1"

Do I need to write a Function?

Brad H.
 
A2K
With Visual Basic code I want to test if a table exists (so I can delete
it). Something like:

IfExists "Table1" Then DoCmd.DeleteObject acTable, "Table1"

Do I need to write a Function?

The general consensus is to turn off error handling prior to deleting (so that
no error message is generated when the table doesn't exist) and then turn error
handling back on:

'***EXAMPLE START
'Initial error handler
On Error Goto MyErrorHandler

[... There may be other code here ...]

'Turn error handling off
On Error Resume Next

'Delete the table
DoCmd.DeleteObject acTable, "Table1"

'Reset error handler
On Error Goto MyErrorHandler
'***EXAMPLE END
 
Back
Top