Checking for Table Existence before deleting

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

John Vinson

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

Jeff Conrad

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
 
R

Rudi

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.
 

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

Top