#SetFocus Bug
4 messages in this thread
I have what seems to be a weird bug when using SetFocus. I have
a form with 2 command buttons and one list. When the form loads
the active control is on the Command1 button. I want the default
active control to be on List1, so I set my last line of code under
SUB Form_load
List1.SetFocus
When running, this gives me an 'Illegal Function Call'. I try to
get around this by changing the focus thru:
SUB Command1_GotFocus
List1.SetFocus
and this works fine except now when I click my mouse over Command1
button, the program doesn't access my code under SUB Command1_Click
or sometimes my mouse cursor just changes to an hourglass and the
computer hangs!
I can get around all of this by putting List1.SetFocus in
SUB Form_Resize and everything works fine.
But why? Anybody know what gives??
<Jerry>
There is 1 Reply.
Jerry,
The problem is that you cannot use .SetFocus until the form (and hence the
control) is visible. There are two solutions to your situation:
1. Place a Show statement at the top of your Form_Load proc
2. Give the desired control a TabIndex of 0 – that will cause it to get the
focus automatically when the form is loaded.
Mark
There is 1 Reply.
Mark, I like the Tabindex. You should start a subsidiary publishing
company with titles like "Even YOU Can Master QBX and VB!!" As alway,
thanks.
There is 1 Reply.
Jerry,
Thanks!
Mark