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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using SetFocus in an OnLostFocus Event - Help 1

Status
Not open for further replies.

jamesu

Technical User
Sep 27, 2001
7
ZA
Hi there

I haven't been able to find an answer to this question, and was hoping someone would be able to help me. I have a text box on a form which I want the user to fill in. In the source table, it is set as a required field, but that doesn't prevent the user from clicking in another field and skipping it. Thus I used the onLostFocus event to check if it is null or blank, and to produce an error message if it is. I then used Me!controlname.setfocus to set the focus back on the text box. It sets the focus on the text box instantaneously, and then returns it to the control which was clicked on to move away from the text box originally. Does anyone know of a better way of forcing users to fill in controls as they move through a form, or of setting the focus to a control after an onLostFocus event.

Thanks

James
 

Use the On Exit event instead of On Lost Focus. If the condition is met, set Cancel=True.

Example:

Private Sub txtGroup_Exit(Cancel As Integer)
If Nz(Me.txtGroup, "") = "" Then
Cancel = True
End If
End Sub
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Hi Terry

Thank you very much for your speedy reply. The solution works perfectly.

Thanks again

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top