Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditonal DeleteObject in MS Access Macros 1

Status
Not open for further replies.

tlham

Programmer
Mar 16, 2006
1
US
I would like to delete a table in an Access Macro to use again. The problem is if the table is not there Access stops with an error. I can not find a conditional statement that will allow me to run the macro, delete the table and continue on whether the table previously existed or not.
 
How about VBA and not Macro?

Code:
Sub KillTable(strTableName As String)

On Error Resume Next
Err.Clear
DoCmd.DeleteObject acTable, strTableName
If Err <> 0 Then
   MsgBox "Table " & strTableName & " Not Found"
Else
   MsgBox "Table " & strTableName & " Found and Deleted"
End IF
End Sub

You could call the Sub from the click event of a button like

Call KillTable txtTableName.Value

using a textbox, named txtTableName, to hold the name of the table to delete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top