How to simple error handling

rehanemis

Registered User.
Local time
Today, 07:44
Joined
Apr 7, 2014
Messages
195
Hi professionals,

Here is simple code in which I running query which updates records in table. I just would like to handle:

When user click on button and ms access shows option that " you are going to append ... records" If I click on No I don't wana see the Error Message with End and debug. I would like to show MS Access default message also and also when user click on No I would like to show customized message.

Private Sub btnMatchLinks_Click()
On Error GoTo CancelOpt
DoCmd.OpenQuery "qryPutXToMatchingRecord"

CancelOpt:
MsgBox "Cancel by User", vbInformation, "Cancel operation"

End Sub

Really waiting of your kind response.
 
Code:
Private Sub btnMatchLinks_Click()
On Error GoTo CancelOpt
DoCmd.OpenQuery "qryPutXToMatchingRecord"

'the 2 lines below will exit the routine graciously if there is no error
[B][COLOR="Purple"]On Error GoTo 0   
Exit Sub[/COLOR][/B]  
 
 'If you add error handling to a function, substitute Function for Sub

CancelOpt:
MsgBox "Cancel by User", vbInformation, "Cancel operation"

End Sub

If you add error handling to a function, substitute Function for Sub
 
Last edited:
but Exit Function is not allowed in Sub and your code is not working.
 
Good point I modified the code in original post.

If you add error handling to a function, substitute Function for Sub.

See the links in my signature for Error Handling and Debugging ideas.
 
Now its working. Thanks a lot.

How I can rating your answer?
 

Users who are viewing this thread

Back
Top Bottom