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

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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.
 
Back
Top