Meaningful Error Message

  • Thread starter Thread starter Pauline C
  • Start date Start date
P

Pauline C

I have a form where I am selecting participant's names for
certain dates (training database) and I have both the
Participant and Date as Primary Keys which works but
instead of the message that comes up I want to substitute
one saying to press Esc or select another name.
The code I have been using is in "After Update" of the
Participant field -

Dim Message As String
On Error GoTo ErrParticipant
ErrParticipant:
Message = MsgBox("You have already selected this
participant, Press Esc or select another Participant")

The problem is that it comes up every time after updating
the field whether there is an error or not. Where am I
going wrong?
 
are you "Exit Sub" somewhere before the "ErrParticipant:"
section?... so the code stops before stepping through the
error code.

drew
 
Pauline,

Your code should look something like:

Private Sub SomeSub_AfterUpdate()

Dim Message As Integer ' An integer value is returned from the
message box function
On Error GoTo ErrParticipant ' Enables error handler

' Procedure statements go here

Exit_SomeSub_AfterUpdate:
' Exit the sub before error handler code runs
Exit Sub

' Error Handler
ErrParticipant:
' Show message to the user
Message = MsgBox("You have already selected this
participant, Press Esc or select another Participant")
' Exit the sub
Resume Exit_SomeSub_AfterUpdate

End Sub

Replace 'SomeSub' with the name of your procedure. Another thing, if you are
trying to validate this field, may I suggest you look into using the
BeforeUpdate event. This has an argument (Integer variable named Cancel).
You can set this variable to True to cancel the update of the field. Might
be a better way of doing things.

HTH,

Neil.
 
Back
Top