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

Set Focus on Combobox 1

Status
Not open for further replies.

Talgo

Technical User
Nov 27, 2003
17
0
0
US
I have a combobox on th main form (TimeCards). I want to check if the field has been left blank before the user proceeds with anymore data entry. So on the Lost Focus event I have the following code:

If Len(Forms!TimeCards!cboEmployee & "") = 0 Then
MsgBox "You must enter a valid EmployeeID before proceeding", vbinformationn + vbOKOnly

Dim frm As Form, cbo As ComboBox

Set frm = Forms![TimeCards]
Set cbo = Forms![TimeCards]!cboEmployee
cbo.Enabled = True
frm.SetFocus
cbo.SetFocus
End If

The problem I'm having is when the user leaves the combobox field blank, all other fields are located on the Subform (TimeCardsSubform). I can't get the set focus to focus back onto the combobox(cboEmployee) located on the Main Form (TimeCards) once it has gone onto the Subform. Can anyone offer a suggestion to get me focused back onto the combobox located on the Main form?
 
Hi!

Since the cbo still has the focus when the lost focus event fires, it won't setfocus to itself.

One of the workarounds are to either create a new very small control to set focus to first, and then set focus to the combo again (or another control on the form, without any code on events can be used for the minimum of time this event uses).

[tt]Set frm = Forms![TimeCards]
Set cbo = frm!cboEmployee
cbo.Enabled = True
frm!txtSomeOtherControl.setfocus
cbo.SetFocus
set frm=nothing
set cbo=nothing[/tt]

HTH Roy-Vidar
 
Hi Roy!

I just tried your suggestion - it worked great. I wrestled with this problem for two days & it took you no time at all to sort out. Where does one learn about these quirks.

I appreciate & give you a star!
 
Thank you for your kind words, and the star!

Glad you made it work, and happy to be of assistance!
(and TT is a marvellous place to find such quirks;-))

Enjoy - Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top