INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

On click navigate to url using webbrowser control

On click navigate to url using webbrowser control

(OP)
I’m using MS Access 2003 with the WebBrowser control on my Form.

When I click command button ‘cmdGo’ the code is supposed to navigate to the ‘URL’ replacing the variables with the values from the appropriate controls on the form. When the page has loaded it should return the ‘result_box’ inner text to the control ‘txtTo’ on the form.

The problem is I can only get it to work by changing Debug.Print to MsgBox in the xWebCtl_DocumentComplete event, but of course the message box is displayed which I don’t want.

I have tried creating Boolean variables and replacing the debug.print line with them but it doesn’t seem to work either. I know the debug.print line isn’t doing anything apart from printing the line but I don’t know what to put there, or even if I need the DocumentComplete event, or if the problem resides in the command button ‘cmdGo’ click code.

If any one knows the correct way to code this or where I’m going wrong I would be grateful.

This is my current code:

CODE -->

Private Sub xWebCtl_DocumentComplete(ByVal pDisp As Object, URL As Variant)
   If (pDisp Is xWebCtl.Object) Then
      Debug.Print "Web document is finished downloading"
   End If
End Sub

Private Sub cmdGo_Click()
Dim URL As String
URL = "https://translate.google.com/#" & Me.cboFrom.Column(1) & "/" & Me.cboTo.Column(1) & "/" & txtFrom

With xWebCtl
     .Silent = True
    .Navigate "about:blank"
Do While .Busy Or .ReadyState <> 4
    DoEvents
Loop
    .Navigate URL, 4 'The 4 turns off caching.
Do While .Busy Or .ReadyState <> 4
    DoEvents
Loop

txtTo = .Document.getElementById("result_box").innertext
'Debug.Print IE.Document.getElementById("gt-sl").Value
Dim str As String
str = .Document.getElementById("gt-lang-left").innertext
txtLangDetected = Replace(str, "EnglishSpanishFrench", "")

End With

End Sub 

RE: On click navigate to url using webbrowser control

Quote (OP)

The problem is I can only get it to work by changing Debug.Print to MsgBox in the xWebCtl_DocumentComplete event, but of course the message box is displayed which I don’t want.

Two things to try given that line:
1. Comment out the Debug.Print and MsgBox as well
2. If #1 doesn't work by itself, try adding DoCmd.Wait where those would run.

I suggest #2 because it sounds to me like for some reason, Access is somehow tripping over itself. I don't see why, but if the Msgbox makes it work, then simply adding a slight pause between the two MIGHT fix it.

Another thing you could try if #2 doesn't work is to add in a line to say txtLangDetected.Select or whatever the correct command is. I don't think this should be required, but again, it's worth a try. If you do go this route, you may also want to capture the name of the currently selected control before this command, and set focus back to the original control.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: On click navigate to url using webbrowser control

You might want to refactor your code a bit.

Consider, given the fact that the tight Do While .Busy Or .ReadyState <>4 loop is simply waiting for the document to complete and that the web browser control already has an event for this (that you are already using), that you might want to eliminate the loops and put most of your code in the event

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close