How to check for Access table in Vb6 at runtime

As we know VB6 let programmer most of the database functions programmatic ways. We are happy to show you a way to check for a tables in your Access database at run time with this tutorial.

As usual we start with a Function, which can be reuse the code, drop the following code in a module.
Function TableExists(databaseName As String, Name As String) As Boolean
‘Table check
Dim TableDb As Database
Dim TableDefinition As TableDef
TableExists1 = False
If Len(databaseName) = 0 Or Len(Name) = 0 Then
 Exit Function
End If

On Error GoTo CheckError
Set TableDb = OpenDatabase(databaseName, , True)
Set TableDefinition = TableDb.TableDefs(Name)
TableExists = True

On Error Resume Next
Exit Function
If err.Number 3265 Then
MsgBox “Error #” & err.Number & ” occured: ” & err.Description
End If
Resume ExitFunction
End Function

The code utilizes Access DAO connection and Access 2003/2007 .mdb database . Just pass the exact path to the database and the name of the table and it will search for the table and return true if the file exist.

I think this will save time of many and will let programmers/poets to enable auto checking for  database application

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in: 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.