how can I check if a table exist?

Insomnia

Registered User.
Local time
Today, 16:27
Joined
Oct 9, 2004
Messages
30
Hi there!

I need to build tables programatically, with different names.
But before I can build one I need to delete any earlier copy with the same name, but I can't delete it if it doesnot exist, and do I found out if it exists??

/thank you Insomnia
 
Code:
Sub TestTable()
    
    If TableExists("table2") = True Then
        MsgBox "table exists"
    Else
        MsgBox "table does not exist"
    End If
    
End Sub
Code:
Public Function TableExists(sTable As String) As Boolean
    
    Dim db As Database
    Dim tbl As TableDef
    Set db = CurrentDb()
    
    TableExists = False
    
    For Each tbl In db.TableDefs
        If tbl.NAME = sTable Then TableExists = True
    Next tbl
    
End Function
 
thx m8, you truly are ghuds son :-)
 
Does table exist in external db

How would I modify this code to test the existance of a table in another (external) database (eg. prior to attempting to import it)?

I've tried replacing .... Set db = CurrentDb() with .....
Set db = "C:\Test\abcdefg.mdb",

... but this results in a "Compile error: Type Mismatch" message.

Thanks for looking.
 

Users who are viewing this thread

Back
Top Bottom