making my own error messages

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

I have a table where the code and lotno are a combined key so there are no
duplicates allowed to be entered. When I use a form for data entry and a
user tries to enter a duplicate code+lotno a criptic error message is
displayed.

How can I interrupt that and display my own error message and then set the
focus on a specific control on the form?
 
first, you need to determine the error code. add the following event
procedure to the form's OnError event, as

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

MsgBox DataErr
Response = acDataErrContinue

End Sub

then open the form in form view and deliberately enter a duplicate combined
key. instead of the error message you've been seeing, you'll get a simple
message box showing the error code.
write down the error code, then go back to design view and replace the
previous event procedure with this:

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

If DataErr = 3022 Then
MsgBox "Put your friendly error message here."
Response = acDataErrContinue
Me!ControlName.SetFocus
End If

End Sub

type your error number in place of 3022. add your custom error message. type
the name of the control you want to go to, in place of ControlName.

also, suggest you read up on the OnError event in Access Help.

hth
 
btw, is there any documentation for the Form_Error
parameters? The new Access """help""" files of course
don't mention a thing, and I can't find any compensatory
kb articles. You're implying that the Response parameter
accepts the same consts as the NotInList event (if my
memory is right)?

Form_Error is v e r y handy for killing the

"The object is locked, so any changes you make will be
discarded when the form is closed.@Click Save As on the
File menu and save the object under a different name"

(error 2800) message when closing a form with filter.
Before, only way I could figure to do this was to hide
the close button & put my own 'close' button with
acSaveNo. I couldn't find a (simple) way to get to
the 'close' message before the Form did.
-Peter
 
Back
Top