Checking if a table exists

A simple error trap with a dlookup will return error 64231 if the table does not exist or the link is broken.


Dim strGetLookupResult As String

On Error GoTo NoTableDetected

strGetLookupResult = DLookup("[Field_Name_Here]", "Table_Name_Here")

Exit Sub

NoTableDetected:

If Err.Number = 64231 Then
MsgBox "Table Does Not Exist"
Else
MsgBox Err.Number & " - " & Err.Description
End If
 
I amended the code to the following:
Code:
Dim str1, str2 As String
On Error GoTo str1Detected
str1 = DLookup("[wcs_sequence]", "[tbl T Number of Seconds Logged On]")
str1Detected:
    If Err.Number = 208 Then
        MsgBox "Table Does Not Exist"
    Else
        DoCmd.RunSQL ("DROP TABLE [tbl T Number of Seconds Logged On]")
    End If
On Error GoTo str2Detected
str2 = DLookup("[wcs_mhe_type]", "[tbl T1 Number of Seconds Logged On]")
str2Detected:
    If Err.Number = 208 Then
        MsgBox "Table Does Not Exist"
    Else
        DoCmd.RunSQL ("DROP TABLE [tbl T1 Number of Seconds Logged On]")
    End If
and it works for the 1st one but then doesn't jump to the error handling for the 2nd one even though the error is 208.

Can anyone help?

Regards
Carly
 

Users who are viewing this thread

Back
Top Bottom