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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top