Determining if a Table Exists

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Is there a preferred way to determine if a table exists. In particular
using the TableDefs collection? Basically, I want to test if a temporary
table (local to the .mdb) exists and if does not, create it.

Thanks!!

Don
 
in message:
Is there a preferred way to determine if a table exists. In particular
using the TableDefs collection? Basically, I want to test if a temporary
table (local to the .mdb) exists and if does not, create it.

Public Function funcTableExists(strTable As String) As Boolean
On Error GoTo ErrorPoint

' This function will check to see if a
' table exists within the current database
' Similar to IsLoaded function it will return True or False
' Jeff Conrad - Access Junkie
' Usage:
' If funcTableExists("SomeTable") = True Then
' ' Table Exists
' Else
' ' Table does not exist
' End If
' **Requires DAO Reference be set**

Dim db As DAO.Database
Dim doc As DAO.Document

Set db = CurrentDb()

With db.Containers!Tables
For Each doc In .Documents
If doc.Name = strTable Then
funcTableExists = True
Exit For
End If
Next doc
End With

ExitPoint:
On Error Resume Next
Set db = Nothing
Exit Function

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function
 
Jeff,

Thanks for the sample code! Pretty much confirmed the direction I thought I
would have to go. Just wasn't sure if some sort of built in ".exists" sort
of method was available.

Thanks again!

Don
 
"Don" wrote in message:
Jeff,

Thanks for the sample code! Pretty much confirmed the direction I thought I
would have to go. Just wasn't sure if some sort of built in ".exists" sort
of method was available.

Thanks again!

You're welcome, glad to help.
 
Back
Top