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

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
 
J

Jeanette Cunningham

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
 
R

Rob W

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
 

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