no focus

  • Thread starter Thread starter Jean-Paul
  • Start date Start date
J

Jean-Paul

I wrote following code:

Private Sub Stop_rit_AfterUpdate()
If Me!Stop_rit < Me!Start_rit Then
If MsgBox("Eind-kilometers zijn lager dan begin-kilometers",
vbExclamation + vbOKOnly, "Let op!") = vbOK Then
End If
End If
Me!Stop_rit.SetFocus
End Sub

When the value of Stop_rit is lower then the value of Stop_rit the
messagebox is displayed... no problem.
I want to give Stop_rit focus again so the user can correct the entered
data.
I always get focus on the following field and not on the Stop_rit field.

What am I doing wrong?
Thanks
 
Jean-Paul said:
I wrote following code:

Private Sub Stop_rit_AfterUpdate()
If Me!Stop_rit < Me!Start_rit Then
If MsgBox("Eind-kilometers zijn lager dan begin-kilometers",
vbExclamation + vbOKOnly, "Let op!") = vbOK Then
End If
End If
Me!Stop_rit.SetFocus
End Sub

When the value of Stop_rit is lower then the value of Stop_rit the
messagebox is displayed... no problem.
I want to give Stop_rit focus again so the user can correct the entered
data.
I always get focus on the following field and not on the Stop_rit field.

What am I doing wrong?
Thanks

Use Stop_rit's BeforeUpdate event instead. There you have the opportunity to
say:

Cancel = True

which prevents the user from moving off the control until it passes your
validation, or presses Esc to undo any changes.
 
Great... problem solved... thanks
JP

Stuart said:
Use Stop_rit's BeforeUpdate event instead. There you have the opportunity to
say:

Cancel = True

which prevents the user from moving off the control until it passes your
validation, or presses Esc to undo any changes.
 
Jean-Paul,
if you put your code in the before update event for the control, you can use
the cancel argument to stop the update.
This will leave the focus back on the control, without you needing to do it.

Private Sub Stop_rit_BeforeUpdate(Cancel As Integer)
If Me!Stop_rit < Me!Start_rit Then
Cancel = True
MsgBox("Eind-kilometers zijn lager dan begin-kilometers",
vbExclamation + vbOKOnly, "Let op!")
Else
End If
End Sub



You almost certainly need to put this code in the before update event of the
form as well.
That will stop the form saving the record if Stop_rit > Start_rit.


Jeanette Cunningham
 
Back
Top