Solved

How to prevent webbrowser ctrl from maintaining focus after navigate?

Posted on 2002-04-10
4
356 Views
Last Modified: 2008-03-03
Hi:

I have a simple project consisting of a textbox, a command button, a webbrowser and a single form on which those three controls are placed.  What happens is the user enters a web address in the textbox and then clicks the command button to navigate.  What I want to happen is for the textbox to regain the focus after the webbrowser finishes navigating.

The code behind the command button looks like this:

-- Begin --

'Perform search
webBrowser.Navigate txtSearchStr 'txtSearchStr = textbox
DoEvents

'Set focus back to the textbox
txtSearchStr.SetFocus

-- End --

This seems to work but if and only if the web page to which the webbrowser navigated does not have a textbox of it's own.  If it does, then the webpage tends to take focus.

I've also tried setting the textbox back to focus in the webbrowser's DocumentComplete and DownloadComplete events but the textbox still doesn't regain the focus.

I would like to allow the webbrowser to have a tabstop if possible.

Looking forward to your replies.

Thanks!

0
Comment
Question by:ksm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
ID: 6931188
Try this
Private Sub WebBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 If (pDisp is webBrowser.object) Then
   txtSearchStr.SetFocus
 End If
End Sub
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6931197
I tried this:

Private Sub txtSearchStr_LostFocus()
  If ActiveControl Is webBrowser Then
    txtSearchStr.SetFocus
  End If
End Sub

CHeers
0
 

Author Comment

by:ksm
ID: 6931499
Interestingly, my original code seems to work today.  However, I think your fine enhancement will help keep the app solid.  So I thank you.
0
 

Author Comment

by:ksm
ID: 6931513
angellll:

I can't use your code.  The reason is because I wanted to still be able to tab to or click on the webbrowser.  With your code, if I click on the webbrowser, the focus jumps back to the textbox.

Thanks, though.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question