Share via

Access - Does an Object Exist?

Anonymous
2013-06-05T01:18:32+00:00

Any code to determine whether a table exists or not before being deleted via vba?

If TableABC.Exists then

DoCmd.DeleteObject acTable, "TableABC"

End If

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-06-05T02:29:05+00:00

The simplest way to do this is just to trap the error and (if you wish) issue a message:

Const NoSuchObject As Integer = 7874 ' error number for Can't Find the Object

On Error GoTo Proc_Error

DoCmd.DeleteObject acTable, "TableABC"

Proc_Exit:

  Exit Sub

Proc_Error:

  Select Case Err.Number

     Case Is NoSuchObject

         MsgBox "As I was going up the stair/I found a table that wasn't there!", vbOKOnly

     Case Else

         MsgBox "Oops, wasn't expecting error # " & Err.Number & vbCrLf & Err.Description

   End Select

   Resume Proc_Exit

End Sub

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful