Check if a table exists using VB

  • Thread starter Thread starter Dave Stevenson
  • Start date Start date
D

Dave Stevenson

Thanks for the replies,

I should have trawled through some of the previous posts
in this newsgroup as exactly the same question was asked a
few days ago !

What I evetually did was :-

On Error Resume Next
Exists = IsObject(CurrentDb.TableDefs(tablename))

If Exists Then
DoCmd.DeleteObject acTable, tablename
End If

On Error GoTo Load_Err '(Usual error handler)

Dave
 
Dave Stevenson said:
I should have trawled through some of the previous posts
in this newsgroup as exactly the same question was asked a
few days ago !

What I evetually did was :-

On Error Resume Next
Exists = IsObject(CurrentDb.TableDefs(tablename))

If Exists Then
DoCmd.DeleteObject acTable, tablename
End If

Dave,

actually, if you _only_ want to delete the table, two lines are
enough:

'Don't bother if Delete bombs because the table
'does not exist
On Error Resume Next

DoCmd.DeleteObject acTable, tablename

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
Van T. Dinh said:
Well ... 3 statements actually since it is more proper to re-set the
error-trapping to the usual error-trapping after (temporarily) setting it to
Resume Next. I normally use:

****
On Error Resume Next
DoCmd.DeleteObject acTable, tablename
On Error GoTo Load_Err '(Usual error handler)
****

Yep, you got to do so, but only if you have a _forth_ line coming
after the Delete :-)))

Have a nice weekend!

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
True. There is no point in resetting the error-trapping if there is no more
statement to be executed.
 
Back
Top