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
‘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
Set TableDb = OpenDatabase(databaseName, , True)
Set TableDefinition = TableDb.TableDefs(Name)
TableExists = True
ExitFunction:
On Error Resume Next
Exit Function
CheckError:
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