T
tlyczko
I have a BeforeUpdate where I need to ensure that no matter what, the
first four fields on the form (one text box, 3 combo box lists) have
data entered in them before the user closes the form or before the user
moves off the form to a subform on the main form, regardless of whether
the end user even put focus to any of the four form fields.
(It is easy to know if all 4 fields have values, but not if less than
four fields have values.)
I've been using code like this in the form's Before Update event (only
one example since the code is the same for all four form fields):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.cboReviewDescription) = True Or
Me.cboReviewDescription.Value = "" Or Len(Me.cboReviewDescription) < 1
Then
Call MsgBox("Please choose a description for this review.",
vbExclamation Or vbSystemModal, "Required Data Entry")
Cancel = True
Me.cboReviewDescription.SetFocus
Me.cboReviewDescription.Dropdown
Exit Sub
End If
End Sub
I have the same kind of in the OnExit event of each of the controls I
need to make sure have data in them.
The code seems to work well for some of the fields, but upon clicking a
btnClose (which does nothing more than close the form's window) neither
the form's BeforeUpdate or the controls' OnExit event works properly,
the message box comes up twice (or more) to be clicked OK, but the
focus does not go back to the form, the form closes without saving any
data.
If the end user doesn't put focus to any of the four controls or focus
to any of the controls on the form, I don't care, but if they have
entered data in only 1, 2, or 3 of the required controls, then I need
to make them go back to the control that needs data entry done.
Basically if data was entered in any 1 or more of the four controls, I
have to validate all four control before closing the form or moving to
the subform.
While typing, I realized I could put some tests into the OnClick event
of the close button control, I will try that now as well.
I've been trying different things for the past day, sigh...I haven't
found anything on the NGs about why my particular code seems to keep
failing, I tried re-compiling, the table for the form's query has the
four fields set to required and not to allow zero length...
Thank you, Tom
first four fields on the form (one text box, 3 combo box lists) have
data entered in them before the user closes the form or before the user
moves off the form to a subform on the main form, regardless of whether
the end user even put focus to any of the four form fields.
(It is easy to know if all 4 fields have values, but not if less than
four fields have values.)
I've been using code like this in the form's Before Update event (only
one example since the code is the same for all four form fields):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.cboReviewDescription) = True Or
Me.cboReviewDescription.Value = "" Or Len(Me.cboReviewDescription) < 1
Then
Call MsgBox("Please choose a description for this review.",
vbExclamation Or vbSystemModal, "Required Data Entry")
Cancel = True
Me.cboReviewDescription.SetFocus
Me.cboReviewDescription.Dropdown
Exit Sub
End If
End Sub
I have the same kind of in the OnExit event of each of the controls I
need to make sure have data in them.
The code seems to work well for some of the fields, but upon clicking a
btnClose (which does nothing more than close the form's window) neither
the form's BeforeUpdate or the controls' OnExit event works properly,
the message box comes up twice (or more) to be clicked OK, but the
focus does not go back to the form, the form closes without saving any
data.
If the end user doesn't put focus to any of the four controls or focus
to any of the controls on the form, I don't care, but if they have
entered data in only 1, 2, or 3 of the required controls, then I need
to make them go back to the control that needs data entry done.
Basically if data was entered in any 1 or more of the four controls, I
have to validate all four control before closing the form or moving to
the subform.
While typing, I realized I could put some tests into the OnClick event
of the close button control, I will try that now as well.
I've been trying different things for the past day, sigh...I haven't
found anything on the NGs about why my particular code seems to keep
failing, I tried re-compiling, the table for the form's query has the
four fields set to required and not to allow zero length...
Thank you, Tom