condition

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Question, I currently have a "DeleteObject" action that
deletes a table in my database "tblSusp", right after that
action I have another action that imports a text file into
a table. The bad thing is that if the table "tblSusp" does
not exist the macro will give an error message and halt
the process. How do I set a condition to where the macro
will bypass the "DeleteObject" action if the
table "tblSusp" does not exist and continue with the
import action?
 
Martin,

An easy way to do it is to use error handling like:

On Error Resume Next
DoCmd.DeleteObject ......
On Error Goto 0 'or to your previous error handler if any

This way the DeleteObject action will simply be ignored if the object does
not exist.

HTH,
Nikos
 
Martin,

This is not possible, directly, with a macro. The best workaround is to
make a Make-Table query, to create a tblSusp table. Then, use an
OpenQuery action in your macro ahead of the DeleteObject action, to run
the Make-Table. If this table already exists, the Make-Table will
overwrite it... which doesn't matter at all, because it's going to be
trashed anyway. If it doesn't already exist, it will now. Either way,
the table will always exist and the DeleteObject will not error. By the
way, you might also want to put a SetWarnings,No action before the
OpenQuery, to suppress the display of the action query confirmation
messages.
 
Back
Top