Question Error handling / custom message question

muckypup

New member
Local time
Today, 07:06
Joined
May 12, 2009
Messages
8
Hello,

Could somebody please help and explain to me the best way to capture and generate a custom message where there has been a key violation.

I have searched through the forum and found a lot of useful information but am having trouble applying it. I feel like I am missing something really simple.:confused: The thread which most closely resembles my issue is entitled 'custom message' posted by xcao on 12/04/03.
 
I believe you have to search for Error Handling. You'll get better results.
 
I believe you have to search for Error Handling. You'll get better results.

Hi Guus, thanks for your reply. I will see if I can find anything to solve my problem using that search term.
 
either

a) explicitly test for potential clash in forms "before update" event or

b) add "error event"

intially just add

msgbox("error: " & err & " Desc: " & err.description)

(offhand might be accesserror, not err - the general error handler works slightly differently)

anyway, this will identify the error NUMBER arising on an insert fail. Then you can change the error message for this particular error to suit yourself.
 
either

a) explicitly test for potential clash in forms "before update" event or

b) add "error event"

anyway, this will identify the error NUMBER arising on an insert fail. Then you can change the error message for this particular error to suit yourself.


Thank you guys for your help. Unfortunately none of the things suggested are working. I think it is because the error handling code is not in the correct place.

My new question. Where are all the 'usual' places to put error handling / message handling code?

This is what should happen: Command button clicked on form 1 which is linked to table 1. Code takes certain values in open form and inserts a new row into table2. Code closes open form and opens form 2 linked to table 2 at the added record. User fills in remaining fields.

This is what happens if there is an key violation:

1) Cmd Button clicked on form 1. Triggers insert into SQL in another table.
Access Msg: 'you are about to append 1 row(s) '

2) User clicks 'Yes' or No' - on click of 'Yes' (if error)

Access Message: 'Microsoft access can not append all of the records in the append query. Microsoft Access set 0 fields to Null ... and it didn't add 1 record(s) to the table due to key violations,... etc'


I have tried the error handling code: on error, before update, before insert, and within the code that generates the insert into query. Nothing, nada, nitch. I can not intercept these messages at all.
 
Last edited:
if you are running docmd.runsql "myquery"
that wont trigger error msgs

instead try

currentdb.execute "myquery", dbfailonerror
 
if you are running docmd.runsql "myquery"
that wont trigger error msgs

instead try

currentdb.execute "myquery", dbfailonerror

Thanks Husky ;)

If I get this thing sorted I will post a concise brief explanation of problem and solution.
 

Users who are viewing this thread

Back
Top Bottom