Deleting a table if it exists, if not don't delete

G

Guest

Good day,
I'm trying to figure out how I can create a macro condition for a delete
command within an Access Macro. I want to delete a table if it exists, but
not attempt to delete the table if it doesn't exist...and therefore escape
any error messages and halting the macro. I've tried messing around with a
few combinations of Dcount as a macro condition, but I can't seem to get it
to work properly. Would someone mind giving me a little push in the right
direction? Thank you much!
 
S

Steve Schapel

AZ,

This is not possible with a macro... not in the way you are trying
anyway. The only way around this that I can think of is to set up a
Make-Table Query to create a table with the name of the table you are
trying to delete. Use an OpenQuery action in your macro to run the
Make-Table before the DeleteObject action. If the table doesn't already
exist, it will now, so the DeleteObject will proceed without error. If
it does already exist, the Make-Table will overwrite the existing, but
that doesn't matter since you are trashing it anyway. You will also
probably want to put a SetWarnings/No action before the OpenQuery, to
suppress the display of the action query confirmation message.
 

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