Hi
If you have reference to the ADO Ext library then this function (from MSDN)
can be modified:
Sub ADOListTables()
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=.\NorthWind.mdb;"
' Loop through the tables in the database and print their name
For Each tbl In cat.Tables
If tbl.Type <> "VIEW" Then Debug.Print tbl.Name
Next
End Sub
Otherwise, you could just search the table for anything. If empty or error
then it doesn't exist:
Function TableXists(strTableName As String) As Boolean
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=.\NorthWind.mdb;"
On Error GoTo Bad
rst.Open _
"SELECT * FROM " & strTableName, _
cnn, adOpenForwardOnly, adLockReadOnly
TableXists = Not (rst.EOF)
rst.Close
Exit Function
Bad:
TableXists = False
End Function
Sub test()
MsgBox TableXists("Customers")
End Sub