How to check Table exist in access database or not?
ms-access, vb6
Solution
Put the function below this one into a public module.
Example code to call the function:
Dim result as boolean
result = IsExistingTable("c:\myFolder\myDatabase.mdb","myTableName")
If result Then
'Do something
Else
'Do something else.
Endif
Function
Public Function IsExistingTable( _
ByVal Database As String, _
ByVal TableName As String _
) As Boolean
Dim ConnectString As String
Dim ADOXConnection As Object
Dim ADODBConnection As Object
Dim Table As Variant
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Database
Set ADOXConnection = CreateObject("ADOX.Catalog")
Set ADODBConnection = CreateObject("ADODB.Connection")
ADODBConnection.Open ConnectString
ADOXConnection.ActiveConnection = ADODBConnection
For Each Table In ADOXConnection.Tables
If LCase(Table.Name) = LCase(TableName) Then
IsExistingTable = True
Exit For
End If
Next
ADODBConnection.Close
End Function
Problem
How to check table exist or not? USING VB 6.0 AND ACCESS 2003 My code. ``` Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\iTDC-ACS.MDB" Cn.Open cmdCardEvent.ActiveConnection = Cn cmd.ActiveConnection = Cn cmdcardevent1.ActiveConnection = Cn cmd.ActiveConnection = Cn cmd.CommandText = "DROP TABLE tmp_cardevent" cmd.Execute cmd.CommandText = "drop table tmp_MOI" cmd.Execute ``` Here I want to check whether table exist then drop table the else no need. How to check table exist or not? Need VB 6 code Help?