Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to prevent webbrowser ctrl from maintaining focus after navigate?

Posted on 2002-04-10
4
Medium Priority
?
359 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
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
hes earned 400 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

926 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