Jeanette,
The App is a continuous form with text boxes that provide numeric data for
calculation and totalizing. It is used to calculate blocks of time that are
applied to work orders in highly skilled manufacturing. The data is
voluntarily deleted completely by the user once the total time to complete a
work order has been calculated and stored in another database. Data entry on
this form needs to be fast and smooth otherwise workers won't use it.
Navigation is done by pressing the Enter key that follows the tab order from
one text box to another and then onto a new record. I have found that the
Exit event is the only event (so far) that successfully prevents a user from
passing by a text box and not entering data. The Before Update event does
not prevent a user from forgetting to change the default value of zero or
null when it is required, thus screwing up the calculation. However, the
Exit event runs whenever a control has focus even when the form is being
spontaneously closed, which is a little confusing for a non-technical user.
When the user closes the form I am assuming they are finished so I don’t want
to prompt them at that point to enter any missing data.
I have tried making the fields required fields but that error message tends
to run after the user has tabbed through all the text boxes which is too late
to be of much use. Validation code in the properties does not prevent any of
the above either. The only solution that seems to more or less work is to
shift focus to the previous control when the Exit event fires but it is still
cumbersome and freakish.
David JJ
Private Sub txtBegHour_BeforeUpdate(Cancel As Integer)
If IsNull(Me.txtBegHour) = True Then
MsgBox "Please enter a Time between 1 - 12", vbOKOnly, "Attention!"
Cancel = True
Me.txtBegHour.Undo
ElseIf Me.txtBegHour <= 0 Or Me.txtBegHour > 12 Then
MsgBox "Please enter a Time between 1 - 12", vbOKOnly, "Attention!"
Cancel = True
Me.txtBegHour.Undo
End If
End Sub
Private Sub txtBegHour_Exit(Cancel As Integer)
If Me.txtBegHour = 0 Then 'when the default value is set to zero
MsgBox "Please enter a Time between 1 - 12", vbOKOnly, "Attention!"
Cancel = True
Me.txtBegHour.Undo
Me.txtLineNum.SetFocus 'the previous control in the tab order
End If
End Sub