Table Exists Condition

  • Thread starter Thread starter JoeCL
  • Start date Start date
J

JoeCL

Hello!

In a macro, If I want to test the existence of a table,
what is the syntax? Like If Table1 exists then...

Thanks.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


In .mdb file types you can check the TableDefs collection. If any error
occurs, it is assumed that the table doesn't exist. This error check
can only be done in VBA. E.g.:

Function IsTable(strTable As String) As Boolean

' Check if the table name in the variable strTable
' exists in the currentdb's TableDefs collection

Dim td As DAO.TableDef

On Error Resume Next
Set td = CurrentDb.TableDefs(strTable)

' If an error occurred IsTable will return False,
' which means the table doesn't exist.
IsTable = (Err = 0)

' Clean up
Set td = nothing

End Function

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQJLmtoechKqOuFEgEQIzBQCg2Pq+qXelRu5H/2Vd6twy8IsQZ18AoI+/
NQP321IUDAKNFtPwFKarZyuW
=yvAm
-----END PGP SIGNATURE-----
 
Back
Top