Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set focus back to textbox if value is null

Status
Not open for further replies.

edge70

Technical User
Aug 5, 2004
15
CA
Hi everyone, I have a little problem when I try to set focus back to the textbox after displaying a message when you try to the next textbox without writing something in the first one.

Here's my code:
Private Sub ZT_Prenom_LostFocus()
If Nz(ZT_Prenom.Value) = vbNullString Then
MsgBox "Vous devez entrer un prénom pour continuer."
ZT_Prenom.SetFocus
End If
End Sub

Can somebody tell me what to do in order to set the focus back to the ZT_Prenom textbox ? ZT_Prenom.SetFocus doesn't work in the actual context.

Thanks
 
How are ya edge70 . . .

Try the following in the [blue]Before Update[/blue] event of [blue]ZT_Prenom[/blue]:
Code:
[blue]   If Trim(Me!ZT_Prenom & "") = "" Then
       MsgBox "Vous devez entrer un prénom pour continuer."
       Cancel = True
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks Aceman, I tried it but I end up with the same results as with my code; if I enter something in the textbox then delete it and try to go on the next textbox using Tab, it works perfectly but if I don't enter nothing and go over the textbox using Tab then it doesn't work, the focus is going to the next textbox.
I need to find a way to set the focus back to the same textbox until the user enters something in it.

Thanks

 
Private Sub ZT_Prenom_LostFocus()
If Nz(ZT_Prenom.Value) = vbNullString Then
MsgBox "Vous devez entrer un prénom pour continuer."
[!]Me![some other control].SetFocus[/!]
ZT_Prenom.SetFocus
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, works just fine now.

Thanks again ! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top