Back To Top


MS Access VBA Check if Table Exists for versions 2000, 2002, 2003, 2007

Go here To Check if Field exists in VBA.
Go here To Update a Field in VBA.
Go here To Get Number of Fields in VBA
Go here To Check if Query Exsists in VBA.

The VBA Check for Table Sample is available for download here in a zipped MS Access Database.

The following code snippet will use VBA to check if a Table exists within the current database.


Function
ifTableExists(TableName As String ) As Boolean
  
Dim
rs As Recordset, Db As Database ' DAO Vars

   'References: Microsoft Access 11.0 Object Library, Microsoft DAO 3.6 Object Library
   'Set references by Clicking Tools and Then References in the Code View window
   'Checks if Table exists in MS Access.
   'USAGE: ifTableExists("TABLENAME")

  
On Error GoTo NoTable 'If there is no table capture the error.

  
Set Db = CurrentDb()

  
'If Table is there open it
  
Set rs = Db.OpenRecordset( "Select * from " & TableName & ";" )
   ifTableExists =
True
  
rs.Close

ExitHere:
  
Db.Close
  
Set rs = Nothing
   Set
Db = Nothing

  
'Notify the user the process is complete.
  
MsgBox "Check for Table Complete"
  
Exit Function

NoTable:
  
'If table is not there close out and set function to false
  
With Err
      MsgBox
"Error " & .Number & vbCrLf & .Description, _
            vbOKOnly
Or vbCritical, "ifTableExists"
  
End With
  
ifTableExists = False
   Resume
ExitHere

End Function



For further help or suggestions go here: MS Access tutorials, Tables, Queries and later: Forms

You may post this tutorial on your website or in a forum. If you do please maintain a Link to Eraseve AP.



For further MS Access tutorials go here: MS Access tutorials

Go here To Check if Field exists in VBA.
Follow the Set Autonumber Field with VBA Link to Set a Field to Autonumber.

 

Did you find what you were looking for?
What would you suggest?
mail@eraserve.com
Your Name:
Your Message:
Your Email:

    

 

Custom Search