how can I check if a table exist? (1 Viewer)

Insomnia

Registered User.
Local time
Today, 22:31
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
 

ghudson

Registered User.
Local time
Today, 16:31
Joined
Jun 8, 2002
Messages
6,194
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
 

Insomnia

Registered User.
Local time
Today, 22:31
Joined
Oct 9, 2004
Messages
30
thx m8, you truly are ghuds son :)
 

st3ve

Registered User.
Local time
Today, 21:31
Joined
Jan 22, 2002
Messages
75
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

Top Bottom