Table exists ??

gmit

Registered User.
Local time
Today, 07:23
Joined
Jan 27, 2004
Messages
23
Hi - Can anyone give me any pointers on how I can check to see if a table exists. I have some code that creates a table but if the table exists already I get an error message. I want to be able to check before the make table code is run.
 
Put this in a module and call it like this:

Code:
If IsTable("tblMyStuff") Then
    ' do stuff
Else
    ' do other stuff
End If


Code:
Public Function IsTable(ByVal strTable As String) As Boolean

    On Error GoTo Err_IsTable

    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    
    Set db = CurrentDb
    
    If db.TableDefs(strTable).Name <> "" Then
        IsTable = True
    End If
    
Exit_IsTable:
    Set tdf = Nothing
    Set db = Nothing
    Exit Function
    
Err_IsTable:
    IsTable = False
    Resume Exit_IsTable

End Function
 
Thanks Mile-O-Phile, I was on the right line but couldn't just get there. It helps with a little clue!
 

Users who are viewing this thread

Back
Top Bottom