Stop macro upon Access error message

J

John Hipskind

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.
 
K

Ken Snell

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.
 
S

Steve Schapel

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
 

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