GotoControl

  • Thread starter Thread starter Clyde Ellingwood
  • Start date Start date
C

Clyde Ellingwood

I have a date field on a form that is required. On the
date field control property On Lost Focus, I check to to
see if its null, then display a message to the user. I
then use the DoCMD.GotoControl "Date Field" to return the
user to the field. What is happening is when I tab from
the date field without entering a date, the control
briefly goes to Date Field but immediately goes to the
next field.

Hopefully this makes sense.

Thanks
 
Clyde,

You would be better to use the Before_Update event of the control. This
allows you to prevent the user leaving the control if certain conditions are
not met.

Private Sub DateField_BeforeUpdate(Cancel as Integer)
If IsNull(DateField) Then
MsgBox "A date is required"
Cancel = True
End If
End Sub

Rod Scoullar
 
Rod

It may be a bit of a problem because the Control_BeforeUpdate does not occur
unless you put something in the Control.

For example, if the Form is on a new Record and if the user enters the
Control and then moves to the next Control without entering anything, the
BeforeUpdate Event won't fire. Alternatively, if the user never goes to
this Control, the BeforeUpdate never fires, either.
 
As explained in the reply to Rod, I don't normally check these until just
before updating the Record into the Table.

I often use the Form_BeforeUpdate Event to check data entry / data
validation for this. Check Access VB Help on the BeforeUpdate Event of the
Form.
 
Back
Top