Stop macro upon Access error message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to stop a macro if the user gets an Access error message.
In my case, I have a macro that imports data from Excel. If the user attempts to import data with a value in a key field that is already in the underlying table, he will get an Access error message, which is fine with me. (I have another macro that deals with that situation, one that uses an update query.)
If he does get such an Access message, I would like the macro to stop (or at least display my own message telling him to use the other macro), rather than the macro continuing on with a message telling him what a great job he did importing data, when in fact he hasn't.
 
Cannot do this with macros.. you must use VBA code to trap errors.

Saying that, if you can identify the situation that causes the error and
handle that via macro, thereby avoiding the error, then you might be able to
use macros.

--
Ken Snell
<MS ACCESS MVP>

John Hipskind said:
I would like to stop a macro if the user gets an Access error message.
In my case, I have a macro that imports data from Excel. If the user
attempts to import data with a value in a key field that is already in the
underlying table, he will get an Access error message, which is fine with
me. (I have another macro that deals with that situation, one that uses an
update query.)
If he does get such an Access message, I would like the macro to stop (or
at least display my own message telling him to use the other macro), rather
than the macro continuing on with a message telling him what a great job he
did importing data, when in fact he hasn't.
 
John,

.... for example, I would always import data into a new table, (or an
existing table only if it is empty!), and then manipulate it from
there into its final resting place. You have much more control over
things that way. In particular, if I correctly understand the
problem, if you import into a blank table and then use an OpenQuery
macro action to run an Append Query to put it where you want, all you
will need is a SetWarnigns,No action before the OpenQuery action to
suppress the action query confirmation message (not really an error
message) that would result from an existing record with the same
primary key value.

- Steve Schapel, Microsoft Access MVP
 
Back
Top