Back To Top


MS Access VBA Check if External 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 Import All Access Files Sample is available for download here in a zipped MS Access Database. The database includes the if External Table Exists code.

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



Function
ifExternalTableExists(TableName As String , spath As String ) As Boolean
  
Dim
rs As Recordset, Db As Database ' DAO Vars
  
Dim strSql As String
  
'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 external MS Access Database.
   'Accepts
   'spath: Complete File Path to external MS Access Database
   'TableName: Name of Table to Look for 
   'USAGE: ifExternalTableExists "TABLENAME", "spath"

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

  
Set Db = CurrentDb()

  
'If Table is there open it
  
strSql = "SELECT * FROM " & TableName & _
        
" IN '" & spath & "'[MS ACCESS;];"
  
Set rs = Db.OpenRecordset(strSql)

   ifExternalTableExists =
True
  
rs.Close
   Db.Close

  
Exit Function

NoTable:
  
'If table is not there close out and set function to false
  
Set rs = Nothing
  
Db.Close
  
Set Db = Nothing

  
ifExternalTableExists = False
   Exit Function
End Function




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