patriciaxxx
Programmer
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:
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 = "[URL unfurl="true"]https://translate.google.com/#"[/URL] & 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