SetFocus misbehaviour

J

JonWayn

I have a pretty simple form that has a WebBrowser control along with 4
command buttons. All controls are placed in the detail section of the form.
In the Open event of the form, I explicitly set focus to the Print button.
However, after the form loads, nothing seems to have the focus and even
hitting the tab key on the keyboard doesnt seem to toggle from one control to
the other as is the expected behaviour. Only after clicking on the detail
section that the focus indicator becomes visible on the Print button. I ahve
used this functionality many times in the past and not have this effect. I
think the use of the WebBrowser control is what introduces this anomalous
behavior. In any event, does anyone here have an explanation and, better yet,
a work-around?

Thanks
 
A

Arvin Meyer [MVP]

Set the Tab Order to the first button. Make sure the others are in the
correct Tab Order and that the have their Tab Stop property set to Yes.
 
J

JonWayn

Thanks for sounding in but that didnt do it though. After some testing I get
to find out that the WebBrowser control is a focus hog. I changed my code by
making the wbc invisible in the load event of the form, forcing the next
control in the tab queue to take the focus. Then, I use the timer event, set
to execute after 5 seconds. When the form loads, you can see the focus taken
by the Print button. But as soon as the wbc appears, the focus gets swept
away. Cant understand why that behavior was programmed into the wbc by
microsoft, but that is how it goes. Any other ideas?

Thanks as always
 
J

JonWayn

If there is some way to programatically click the detail section of the form
after it loads that may do the trick. How can that be acomplished?
 
A

Arvin Meyer [MVP]

You can't click the detail section, but if you have code in that section,
you can run it in response to another action. For instance, if you had code
in a command button to do an event, you can begin that even by running the
same code as in the detail section. It might look something like:

Private Sub cmdNavigate_Click()

Detail_Click

If Not IsNull(Me.txtURL) Then
With Me.ActiveXCtl_IE
.Navigate Me.txtURL
End With
End If

End Sub


The Detail_Click sub call will run first, then button will run the Navigate
code in the ActiveXCtl_IE control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top