Checking for Table Existence before deleting

  • Thread starter Thread starter Joey
  • Start date Start date
J

Joey

Hello All,

I would like to check to see if a table exists first before deleting it
(to avoid an error). How would I do this? It seems like this should be
an easy task.

Thanks,
Joey.
 
Hello All,

I would like to check to see if a table exists first before deleting it
(to avoid an error). How would I do this? It seems like this should be
an easy task.

Thanks,
Joey.

It's easiest to simply use error trapping to detect the error, and
either issue a message friendlier than the Access default or simply
Resume Next.

John W. Vinson[MVP]
 
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

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

I had a similar question and solved it like this :

Perform a command on the table and trap the error that comes when
table doesn't exist.

For instance : VarDummy=dcount("[field1]";"Table1")

If the table doesn't exist, a trapable error occurs.

This seems workable to me.....(Hope I'm right)

Regards,
Rudi.
 
Back
Top