How to check if a Table exist on Microsoft Access using VBA

In order to check if a Table exist on a Database (MS Access), we can use Function in VBA. Its pretty simple and I think most of you can easily learn and apply this on your own project. The idea of this function on this tutorial is to check if a table exist by typing the table name on a Textbox. See my project example here.

check if table exist

Now, here is the code. This code will be executed when Check Table button is pressed to check if table name on the text box exist in the database.

[codesyntax lang=”vbnet”]

Private Sub Command0_Click()
On Error GoTo Bed
If TableCheck(Me.Text2.Value) = True Then
MsgBox (Me.Text2.Value & " exist")
Else
End If
Exit Sub
Bed:
MsgBox Err.Description
End Sub

'Function to check table
Function TableCheck(TblName As String) As Boolean
On Error GoTo Bed
Dim x
x = DCount("*", TblName)
TableCheck = True
Exit Function
Bed:
MsgBox "Table " & Me.Text2.Value & " does not exist"
TableCheck = False
End Function

[/codesyntax]

Result

check if table exist vba

Admin

Leave a Reply

Your email address will not be published. Required fields are marked *