Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Trapping-Key violations, Lock violations, etc

Status
Not open for further replies.

Jacqui3

MIS
May 8, 2002
13
0
0
ZA
Hi,

I would like to know how I can trap the errors relating to the following types of errors:
-type conversion failure,
-key violations
-lock violations
-validation rule violations

 
In either a form or module, you can trap the errors. You need to use the OnError event in a form, if the error when a user editts a record. You will need to know the error number to determine the type of error. During the OnError event, Access passes the variable DataErr (Integer) to the sub routine. DataErr is the error number that access would display. For more information, look up the OnError event in Access help.

For Modules, you need to use the Err object. Err.Number will return the error number when VBA code from a module, class module or a form class module generates the error.

Let me know if you need more help. You may be able to take this information and run with it (with a little help from Access help).
God Bless,
Mike

Yes, I believe in Jesus. ;-)
"Neither is there salvation in any other: for there is none other name under heaven given among men, whereby we must be saved." (Acts 4:12, KJV)
 
Mike,

I have a button on a form that appends records to a table. What I am trying to do is replace the MS access error message when there are problems with the append.

Here is my code, I tried to use the help but it does not seem to be working -
Private Sub Command3_Click()
Dim Response, strMsg As String
strMsg = "Test"
SetOption "Confirm Action Queries", False
DoCmd.OpenQuery "LARuploadAppendToEtes", acViewNormal, acEdit

On Error GoTo ErrorHandler
SetOption "Confirm Action Queries", True
Response = MsgBox("Etes Updated excluding Errors", vbInformation, "Update eTES from LAR spreadsheet")

Exit Sub ' Exit to avoid handler.
ErrorHandler:
' Display error information.
MsgBox "Error number " & Err.Number & ": " & Err.Description
' Resume with statement following occurrence of error.
Resume Next

End Sub

Also, what are the error codes for -
- type conversion failure
- key violations
- lock violations
- validation rule violations
 
I am not sure why you would need a error handler. If you editted the underlying query to contain a left join from the append source to the append destination where the append destination's key is null, you would never have a primary key error. You can take similiar steps to remove all occurances of errors.

Are you wanting the user to know there was an error, or would you rather prevent the error from happening in the first place? If this question sounds rhetorical, that is not my intention. I am just simply trying to determine if you have a specific reason why you want an error to occur. God Bless,
Mike

Yes, I believe in Jesus. ;-)
"Neither is there salvation in any other: for there is none other name under heaven given among men, whereby we must be saved." (Acts 4:12, KJV)
 
After reading my last post, it really seems like I need a sense of humor. LOL God Bless,
Mike

Yes, I believe in Jesus. ;-)
"Neither is there salvation in any other: for there is none other name under heaven given among men, whereby we must be saved." (Acts 4:12, KJV)
 
Mike,

I want the user to know there is an error.

Can you help me out? My VB is extremely limited.

Jacqui
 
In the errHandler you can put the code
if err.number = <number> then
response = acdataerrcontinue
Msgbox &quot;Put your own message here&quot;
resume next
elseif err.number = <number> and so on
else
msgbox err.description & err.number
resume next
end if

If it isn't brief enough, tell me, I hope can help u further
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top