Check if a particular table exists in MS Access Database.

Check if a particular table exists in MS Access Database.

Function is written to check whether a table exists or not.

Function tblExists(chkTblNm as String) as Boolean .

Step 1 : Variables are declared

Dim tblFound as Boolean
Dim dbs as DAO.Database
Dim tbl as DAO.TableDef
On Error Go to Err_Line

tblFound = False

step 2 : set to access the current database

Set dbs = Access.CurrentDb

Step 3 : for each table in the dbs , compare with and if found any name same tblfound is set to true
For Each tbl in dbs.TableDefs
If tbl.Name = chkTblNm Then
tblFound = True
Exit For
End If

Step 4: tblfound Boolean value is assigned to tblExists

tblExists = tblFound

Step 5 : set tbl and db to nothing and if found errors accordingly display error number and description
Set tbl = Nothing
Set db = Nothing
MsgBox "Error " & Err.Number & "-" & Err.Description
Resume Exit_Line

End Function


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: