Can you check if an object exists, and only it it does, delete it

G

Guest

Can you check if an table object exists within a macro, and only it it does, delete it...if it doesnt exist, then just ignore it

THANK YOU ANYONE!
 
S

Steve Schapel

Craig,

As far as I know, there is no code-free way to do this directly. One
way around it is to set up a Make-Table Query to make a table with the
name of the one you want to delete, and use a RunQuery action in your
macro to make the Make-Table Query happen before your DeleteObject.
If the table already exists, it will be overwritten by the new one...
but that doesn't matter because you are deleting it anyway. If it
doesn't exist already, it will, and thus the delete will go ahead
without error.

- Steve Schapel, Microsoft Access MVP
 
J

Jim/Chris

I don't know how to do it in a macro but here is some
simple code that you can put in your On_Click event that
will delete the table. If the table does not exist it just
continiues on.

Private Sub Command12_Click()
On Error Resume Next

DoCmd.DeleteObject acTable, "tablename1"
DoCmd.DeleteObject acTable, "tablename2"

Beep
MsgBox " tablename1 & tablename2 have been deleted"

delete_object_Exit:
Exit Sub

delete_object_Err:
MsgBox Error$
Resume delete_object_Exit

End Sub

Jim
-----Original Message-----
Can you check if an table object exists within a macro,
and only it it does, delete it...if it doesnt exist, then
just ignore it
 

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