customize error msg

G

Guest

I have a working table and my primary table. I created an append query to
append the record if not a duplicate based on primary key, which is made up
of two fields. I get the error msg saying it can not append and all but I
would like to customize that msg and return the user back to the form to try
again.
 
G

Guest

Find out what the error number is, then trap it in the form's error Event
Procedure like so:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

if DataErr = whatever the error number is
MsgBox "The message you want the user to see"
Response = acDataErrContinue
end if

End Sub

To find out the error number you need to have an 'on error' statement at the
beginning of the sub/function (or somewhere before the statement that causes
the error):

On Error GoTo HandleError

What I do is at the bottom of my sub (or function) I have an Exit statement
for the sub/function followed by the HandleError label. SOmething like this

code....

Exit Sub

HandleError:
msgbox Err.Number

End Sub
 
G

Guest

The error message does not give a number. It's just an information message.
I'm sorry, I should have explained that better. I'm running an append query
and when it's run with duplicate in the key, I get the message that says
Microsoft Office Access ..... can't append all the records in the append
query.
....
....
Do you want to run the action query anyway?
To ignore the error(s) and run the query, click Yes.
For an explanation of the cuases of the violations, click Help.

It does not add the record even if you click yes becuase of the primary
fields, however I would like to send the user a message and return them to
the form.
 

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