Check if a table exists using VB

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
 
E

Emilia Maxim

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
 
E

Emilia Maxim

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
 
V

Van T. Dinh

True. There is no point in resetting the error-trapping if there is no more
statement to be executed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top