Error Handling: When adding data where data is incomplete/incorrect.

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

I added my error checking (see code below) on the Form "On Current" event as
I believe this code will run upon any action on screen being actioned.

Errors happen when users are adding incomplete/incorrect data then pressing
the next navigation button which adds a record if it is the last record.

Where is best to put my error validation?
Thanks Rob


Private Sub Form_Current()

On Error GoTo MyErr

ExtenuatingCount = DCount("[StudentID]", "tblStudentsResultsDelivery",
"[StudentId]= '" & [txtStudentId] & "' AND [ExtenuatingCircumstances] =
True")

If ExtenuatingCount > 0 Then
Me.lblExtenuating.Visible = True
Else
Me.lblExtenuating.Visible = False
End If

MyExit:
Exit Sub

MyErr:
MsgBox "Please check all information is correct and present",
vbExclamation
Me.txtStudentId.SetFocus

Resume MyExit

End Sub
 
Rob,
error validation goes on the Before Update event of the form ( not a
control).
The before update has a cancel argument.
If the validation fails, put Cancel = True and a msgbox to tell the user
about the problem.
Once the update of the form is cancelled, the data is not saved to disc and
users are prevented from going to the next record

Jeanette Cunningham
 
Thanks very much. Will look into this.

Jeanette Cunningham said:
Rob,
error validation goes on the Before Update event of the form ( not a
control).
The before update has a cancel argument.
If the validation fails, put Cancel = True and a msgbox to tell the user
about the problem.
Once the update of the form is cancelled, the data is not saved to disc
and users are prevented from going to the next record

Jeanette Cunningham


Rob W said:
Greetings,

I added my error checking (see code below) on the Form "On Current" event
as I believe this code will run upon any action on screen being actioned.

Errors happen when users are adding incomplete/incorrect data then
pressing the next navigation button which adds a record if it is the last
record.

Where is best to put my error validation?
Thanks Rob


Private Sub Form_Current()

On Error GoTo MyErr

ExtenuatingCount = DCount("[StudentID]", "tblStudentsResultsDelivery",
"[StudentId]= '" & [txtStudentId] & "' AND [ExtenuatingCircumstances] =
True")

If ExtenuatingCount > 0 Then
Me.lblExtenuating.Visible = True
Else
Me.lblExtenuating.Visible = False
End If

MyExit:
Exit Sub

MyErr:
MsgBox "Please check all information is correct and present",
vbExclamation
Me.txtStudentId.SetFocus

Resume MyExit

End Sub
 
Back
Top