How to find out if a given table exists (with VBA code) ?

G

Guest

Hi

What's the quickest and most elegant way to find out with VBA code if a
given table exists in an Access DB ?

I need to find out if a table exists, so that I can delete it before
recreating it by reading it from an external DB.

So far, I've used a clumsy method with DoCmd.OpenTable. It works if the
table exists. If it doesn't exists, although I have put an "On Error GoTo"
just before the DoCmd, I get an error, i.e. the On Error doesn't work !

Thanks for help
Balex
 
A

Allen Browne

Function TableExists(strTable As String) As Boolean
Dim strDummy As String
On Error Resume Next
strDummy = CurrentDb.TablesDefs(strTable).Name
TableExists = (Err.Number = 0)
End Sub
 

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