MS Access Application: How can I use VBA to check if a table already exists?

This lesson comes as part of a series on building Microsoft Access Applications

There may come a time where you’re creating an MS Access application and you need to systematically check to see if a table already exists.

This handy function does just that.

It’s simple, and effective – which is the best kind of code.

Just add this function to a module in your VBA.

Function TableExists(strTableName As String) As Boolean
On Error Resume Next
TableExists = IsObject(CurrentDb.TableDefs(strTableName))
End Function

Then use the below method to check to see if that table exists:

If TableExists("My_Table_Name") = False Then 'Change the table name to your table
     'Do Something Fun
     'Do Something Else Fun
End If

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s