Hi,
I was wondering if i could get some help with the form.
I'd like to be able to take the cursor back to the text-box where there is
an error. The error may be produced because the entry data doesn't satisfy
the condition.
For example, there is a textbox called age. I have the following code
Private Sub Age_Exit(Cancel As Integer)
If Me.Age < 20 Then
MsgBox "The age cannot be less than 20. Please check it again"
End If
me.Age = "" ' Clear the box
End Sub
How do i get the cursor back to the Textbox - age? i have tried to use
.setfocus but to no avail.
Thank you in advance
Allen Browne - 25 Feb 2008 08:15 GMT
Add the line:
Cancel = True
It might be better to use the BeforeUpdate event procedure of the control.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> I was wondering if i could get some help with the form.
>
[quoted text clipped - 16 lines]
>
> Thank you in advance
Steve Schapel - 25 Feb 2008 08:21 GMT
Associates,
As an aside, you wouldn't try to set the textbox's value to "" a
zero-length string. This line in your code should be:
Me.Age = Null
In any case, I am going to suggest another approach, namely to use the
Before Update event to make this check. Something like this:
Private Sub Age_BeforeUpdate(Cancel As Integer)
If Me.Age < 20 Then
MsgBox "The age cannot be less than 20. Please check it again"
Cancel = True
Me.Age.Undo
End If
End Sub

Signature
Steve Schapel, Microsoft Access MVP
> Hi,
>
[quoted text clipped - 18 lines]
>
> Thank you in advance