PDA

View Full Version : Problem with SetFocus



pcsparky
11-03-2009, 07:56 AM
I have the following code in the form Navigation:


Private Sub UserForm_Initialize()
Dim i As Integer
instructorComboBox.SetFocus 'Set Focus on Instructor ComboBox
dateLBL.Caption = Format(Now, "d mmmm yyyy") 'Set todays date
Call Fill_handlerListBox 'Populate the Handler ListBox
For i = 0 To 3
Navigation.MultiPage2.Pages(i).Caption = UCase("Dog Type")
Next i
End Sub

Yesterday, the SetFocus was working for the instructorComboBox, whereby the vertical line was flashing ready for input. Now it is not.
I have tried both Me. and Navigation. before that line of code but that makes no difference. It is visible and enabled.

It does work in the Userform_Activate sub but that's not where I want it.
Any ideas.

lucas
11-03-2009, 08:01 AM
is the combobox on one of the pages? Is that page open when the userform loads?

Post it so we can look at it.

pcsparky
11-03-2009, 08:36 AM
Think I've attached it properly.

No the combobox is not on any of the multipages and I've searched the whole project to make sure that SetFocus is not set for anything else.

lucas
11-03-2009, 10:15 AM
attach your workbook please.

pcsparky
11-03-2009, 10:35 AM
Here goes

lucas
11-03-2009, 11:25 AM
It does work in the Userform_Activate sub but that's not where I want it.


Why not. It does work there. I think you have the combobox hidden or something. I have to move a label just to see it.

pcsparky
11-03-2009, 01:03 PM
I don't want it in Userform.Activate because I don't want it to setfocus when the user returns to the form having done something else, only at start up.

I moved the other label completely out of the way but that doesn't help and it is definitley not hidden in the properties.

I've just tried changing the setfocus to one of the buttons and that doesn't work either. Perhaps SetFocus can't be used in Initializing the form.

Tinbendr
11-04-2009, 06:17 AM
Could you make it conditional?

Private Sub UserForm_Initialize()
'...
If instructorComboBox.Tag = "" Then
instructorComboBox.SetFocus 'Set Focus on Instructor ComboBox
End If
instructorComboBox.Tag = "STARTED"

Funny, I can't get the cursor to blink in Initialize, but it definitely has the focus. Then, I'm looking at it in 2003.

If I change the instructor's name, the closeSystemBtn gets the focus. Strange. But the workaround is, in the changeInstrBtn_Click add...
SendKeys "{TAB}"
Seems to me, that in Office 97 days, we had to use the Sendkeys as a workaround. (But I can't find that reference anymore.) Set the focus on the last action object and send a tab.

Hope this helps!

pcsparky
11-04-2009, 07:48 AM
Thanks for your efforts.

I thought the combobox may be somehow corrupted as SetFocus works fine in a blank workbook but when trying to setfocus on a new combobox in the userform it still doesn't work.

Perhaps the userform is corrupted. I will go through my code with a fine toothcomb to see if I can see what may be causing the problem, failing that it's not all that important.