Discussion Locked

Custom Error Messages

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am currently using access 97 and would like to know if any one knows of a way to generate custom error messages for Duplicate entries. The records are indexed with no duplicates on a couple of fields, and the data is entered on a form. If a duplicate value is entered the only message that we currently get is that when you attempt to continue it says : "You can't go to the specified record. You may be at the end of a record set. "
Any help would be greatly appreciated. Thank you.

2 replies

by timfox

Your question poses two answers:
1. How do I trap an error?
To trap any event you have to know what is occurring in your application (front end) and the database (backend) to know which events are occuring. So the answer (for your example) lies inthe events of the form that you are entering data on. Where exactly depends on what you are doing when 'you attempt to continue'. (Unless the error occurs within code, look at the events that are available for the form.) If the event is actually occuring before the update, then look at the individual field events. When mulitple events occur one after the other, locate the event that you want to handle by understanding the reason each event is occuring (sometimes they may appear to be similar, but all are different - on-line help is very good here).

- continued in next thread -

by timfox

- continued from previous thread -

2. How to handle an event.
Two ways to handle events - proactive and reactive. (best to use a combination)
-A proactive approach means determining whether an error will occur and dealing with the error situation to avoid it by either changing data values to avoid the error or cancelling the event/action that caused the error to occur (not all events can be cancelled) and reporting the error situation to the user.
- A reactive approach will usually invoke an error within your code that adds/edits/calculates/deletes etc and should be picked up in the following construct of a function:
-------
Private Sub ThisFunction (strThisValue As String) As Boolean

dim strFunctionName as String
strFunctionName = "ThisFunction"

On Error GoTo Err_ThisFunction

Exit_ThisFunction:
Exit Sub

Err_ThisFunction:
Select Case Err.Number
Case 1
MsgBox "Error Type 1 has occurred.", vbCritical, strFunctionName
Case 4576
Msgbox etc
End Select
Resume Exit_ThisFunction
-------

In your example, it appears as thought your application is attempting to move past the end of the current recordset - but I can't determine why without looking at the code itself. Perhaps other readers can figure out the exact reason...

Hope it all helps - good luck.

This discussion is closed to new replies.