Form Level Validation vs Control Level Validation in Form/Subforms

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

"Save button madness" here

I am working with a form / subform (continuous form) arrangement, and trying
to put together relatively bulletproof validation. Of course, with bound
forms, there is no "save" button, and thus (I believe) forrm level
validation (ie. testing of all controls before saving) is not possible.

I have spent about three or four days experimenting with , in particular,
the before update event. This simple code does not appear to prevent the
user from entering nothing into a field. Here is a sample


Private Sub txtSex_BeforeUpdate(Cancel As Integer)
If IsNull(txtSex.Value) Or txtSex.Value = "" Then
MsgBox "Vous devez mettre la sexe de l'animal", , aTitle
Cancel = True
End If

If Not (UCase(txtSex.Value) = "F" Or UCase(txtSex.Value) = "M") Then
MsgBox "vous devez mettre 'M'[male] ou 'F' [ female]", , aTitle
Cancel = True
End If
End Sub

The event works if I enter something into the text field, and then erase it
(the isnull part anyway)), but does not prevent the user from clicking
around the particular text box to another, or even tabbing through an empty
textbox. Is there something I'm missing here that would avoid this kind of
problem in a form / subform arrangement.? Or is it back to creating that
save button with unbound forms and temporary tables?

John S
Aylmer, PQ
 
John S said:
"Save button madness" here

I am working with a form / subform (continuous form) arrangement, and trying
to put together relatively bulletproof validation. Of course, with bound
forms, there is no "save" button, and thus (I believe) forrm level
validation (ie. testing of all controls before saving) is not possible.

I have spent about three or four days experimenting with , in particular,
the before update event. This simple code does not appear to prevent the
user from entering nothing into a field. Here is a sample


Private Sub txtSex_BeforeUpdate(Cancel As Integer)
If IsNull(txtSex.Value) Or txtSex.Value = "" Then
MsgBox "Vous devez mettre la sexe de l'animal", , aTitle
Cancel = True
End If

If Not (UCase(txtSex.Value) = "F" Or UCase(txtSex.Value) = "M") Then
MsgBox "vous devez mettre 'M'[male] ou 'F' [ female]", , aTitle
Cancel = True
End If
End Sub

The event works if I enter something into the text field, and then erase it
(the isnull part anyway)), but does not prevent the user from clicking
around the particular text box to another, or even tabbing through an empty
textbox. Is there something I'm missing here that would avoid this kind of
problem in a form / subform arrangement.? Or is it back to creating that
save button with unbound forms and temporary tables?

You're using the BeforeUpdate event of the *control*, therefore if the
control is never updated it doesn't fire. This is when you need to use the
BeforeUpdate of the *form*. You're assertion hat this is not possible with
bound forms is incorrect.
 
Further to what Rick said, you could code the Form_Error event to trap any
erros that pass by your BeforeUpdate va;lidation. Bear in mind that it would
not be feasible for BeforeUpdate to check fort >every possible error< that
might occur. So you must assume that some will drop through. You can trap
those with Form_Error.

HTH,
TC
 
Do your validation on the FORM BeforeUpdate event
This is at best Pseudo Code, but it will give you the idea.

For each ctl in me.controls
if ctl.Tag = "Required"
if isNull(ctl.Value) or ctl.Value = "' then
ctl.BackColour = cRed
Cancel = true
strOneBadControl = ctl.Name
else
ctl.BackColour = cNormal
endif
if Cancel then
MsgBox "Merde"
me.Controls(strOneBadControl.SetFocus
endif
next ctl
YOu can check normal ranges of data as it is entered in the controls
BeforeEvent
 
Thank you both; I will try the update property of the form. Ongoing
education.

John S
Aylmer, PQ


TC said:
Further to what Rick said, you could code the Form_Error event to trap any
erros that pass by your BeforeUpdate va;lidation. Bear in mind that it would
not be feasible for BeforeUpdate to check fort >every possible error< that
might occur. So you must assume that some will drop through. You can trap
those with Form_Error.

HTH,
TC


John S said:
"Save button madness" here

I am working with a form / subform (continuous form) arrangement, and trying
to put together relatively bulletproof validation. Of course, with bound
forms, there is no "save" button, and thus (I believe) forrm level
validation (ie. testing of all controls before saving) is not possible.

I have spent about three or four days experimenting with , in particular,
the before update event. This simple code does not appear to prevent the
user from entering nothing into a field. Here is a sample


Private Sub txtSex_BeforeUpdate(Cancel As Integer)
If IsNull(txtSex.Value) Or txtSex.Value = "" Then
MsgBox "Vous devez mettre la sexe de l'animal", , aTitle
Cancel = True
End If

If Not (UCase(txtSex.Value) = "F" Or UCase(txtSex.Value) = "M") Then
MsgBox "vous devez mettre 'M'[male] ou 'F' [ female]", , aTitle
Cancel = True
End If
End Sub

The event works if I enter something into the text field, and then
erase
it
(the isnull part anyway)), but does not prevent the user from clicking
around the particular text box to another, or even tabbing through an empty
textbox. Is there something I'm missing here that would avoid this kind of
problem in a form / subform arrangement.? Or is it back to creating that
save button with unbound forms and temporary tables?

John S
Aylmer, PQ
 
Hi guys,

Unfortunately, the newsgroup is being subject to my "just in time" (or a
little late) learning. What I have done, which seems to work, is to use the
exit event for control level validation, and form before update event for
form level validation. I have absolutely no idea of the difference between
the form beforeupdate and the form_error events.

Perhaps its time for another stroll through google.

Thanks

John S
Aylmer, PQ

TC said:
Further to what Rick said, you could code the Form_Error event to trap any
erros that pass by your BeforeUpdate va;lidation. Bear in mind that it would
not be feasible for BeforeUpdate to check fort >every possible error< that
might occur. So you must assume that some will drop through. You can trap
those with Form_Error.

HTH,
TC


John S said:
"Save button madness" here

I am working with a form / subform (continuous form) arrangement, and trying
to put together relatively bulletproof validation. Of course, with bound
forms, there is no "save" button, and thus (I believe) forrm level
validation (ie. testing of all controls before saving) is not possible.

I have spent about three or four days experimenting with , in particular,
the before update event. This simple code does not appear to prevent the
user from entering nothing into a field. Here is a sample


Private Sub txtSex_BeforeUpdate(Cancel As Integer)
If IsNull(txtSex.Value) Or txtSex.Value = "" Then
MsgBox "Vous devez mettre la sexe de l'animal", , aTitle
Cancel = True
End If

If Not (UCase(txtSex.Value) = "F" Or UCase(txtSex.Value) = "M") Then
MsgBox "vous devez mettre 'M'[male] ou 'F' [ female]", , aTitle
Cancel = True
End If
End Sub

The event works if I enter something into the text field, and then
erase
it
(the isnull part anyway)), but does not prevent the user from clicking
around the particular text box to another, or even tabbing through an empty
textbox. Is there something I'm missing here that would avoid this kind of
problem in a form / subform arrangement.? Or is it back to creating that
save button with unbound forms and temporary tables?

John S
Aylmer, PQ
 
Back
Top