Import: check if table existed

G

Guest

Hi all,

I was able to import 7 tables from a .mdb file to a current database (import
to temp tables, then use Insert, then delete the temp tables -I do have a
check for table function to check if the table existed to check if the temp
tables are there so I can delete to avoid temp1, temp2...but it only work
with current connection.) Right now if I pick a wrong .mdb (doens't have 7
tables as my current connection) then a system message turn on and it will
exit the function. So I want to see if I can check that .mdb file have those
table or not so I can force user to pick the right .mdb file... Anyway know
how to check a givien location to see if there is table please help...

Thanks in advance...
Violette
 
B

Brendan Reynolds

Public Function ContainsTable( _
ByVal PathName As String, _
ByVal TableName As String _
) As Boolean

Dim db As DAO.Database
Dim tdfs As DAO.TableDefs
Dim tdf As DAO.TableDef

Set db = DBEngine.OpenDatabase(PathName)
Set tdfs = db.TableDefs
For Each tdf In tdfs
If tdf.Name = TableName Then
ContainsTable = True
Exit For
End If
Next tdf
db.Close

End Function

Examples of use, in the Immediate Window ...

? ContainsTable("C:\Program Files\Microsoft
Office\Office11\Samples\Northwind.mdb", "Customers")
True
? ContainsTable("C:\Program Files\Microsoft
Office\Office11\Samples\Northwind.mdb", "No Such Table")
False
 
G

Guest

Thank you Brendan, your function works like charm!!!
Appreciated your help,
Violette
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top