Custom error coding doesn't work...WHY?

S

Sidz

Hi,
I have this error coding in my form:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3201 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please fill in all the fields" ' Display your own message
Else
If DataErr = 3317 Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please fill in all the date field" ' Display your own message
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

End Sub

However, in one of the date/time controls in this form, there is a table
level validation rule. If I violate that rule, the error message "3317" is
shown. For some reason, my custom error message for that error in the above
code, is ignored!!

I can't move the validation rule to the form level, since this control is
updated by the value from a calender control. If I type in the value for the
date/time field, then the error following error message is displayed:

Block If End If

!!??? I am totally confused! Please help
 
J

John Nurick

Hi Sidz

Does that Form_Error procedure actually compile? It looks to me as if
there's an End If missing somewhere. That would account for the error
message you are getting.

Usually it's simpler to use a Select Case structure, e.g.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3201
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please fill in all the fields" ' Display your own message
Case 3317
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please fill in all the date field" ' Display your own
Case Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End Select
End Sub
 
S

Sidz

umm....The select structure still doesn't make a difference! The default
error message for error 3317 still is shown!
 
S

Sidz

If I type in the values, then the custom error message work. If i try to
choose the dates from the Calender control, the defulat error message is
shown.

Just to remind you guys, the date/time control (Event Date) has the control
source from the table 'tblBookings', but it is also updated as I click on a
different date on the calendar control!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top