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

SetFocus not working in data entry code

Status
Not open for further replies.

LeoLily

Technical User
Jun 30, 2005
9
US
I am creating a data entry form with required fields. I have set data entry code in the "On Exit" as follows:

Private Sub responsible_Exit(Cancel As Integer)
If IsNull(Me.responsible) = True Then
MsgBox "Click on Responsible level."
Me.responsible.SetFocus
End If
End Sub

The problem is that the SetFocus is placing the focus on the next field instead of the referenced field. Any suggestions? I was thinking to add code after the SetFocus line to force the cursor to move to the next field, but am not sure how to write it.
 
MsgBox "Click on Responsible level."
Me![any other control].SetFocus
Me.responsible.SetFocus

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
BTW, much simpler:
Private Sub responsible_Exit(Cancel As Integer)
If IsNull(Me.responsible) = True Then
MsgBox "Click on Responsible level."
Cancel = True
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried the first fix and it worked perfectly! Thanks SO MUCH!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top