Hello,
I hope someone can assist me with this.
I am simply trying to find text on a Web Browser Control htm page.
Using MS Access 2003, I have a form that includes the activeX Web Browser Control. On load of the form I initialize the web like below:
The page loads fine.
Now, also, on my form is an unbound text box I call: [txtFind] and a command button I call [cmdFind]. I want [cmdFind] to find the first occurrence of the value in [txtFind]. My code below doesn't do anything when I click the [cmdFind] button. Can someone tell me what I'm doing wrong? Thanks in advance.
I hope someone can assist me with this.
I am simply trying to find text on a Web Browser Control htm page.
Using MS Access 2003, I have a form that includes the activeX Web Browser Control. On load of the form I initialize the web like below:
Code:
Dim strURL As String
strURL = "[URL]http://www.justice.gov/eoir/profcond/chart.htm[/URL]"
Me.WebBrowser0.Navigate strURL
Me.WebBrowser0.Silent = True
The page loads fine.
Now, also, on my form is an unbound text box I call: [txtFind] and a command button I call [cmdFind]. I want [cmdFind] to find the first occurrence of the value in [txtFind]. My code below doesn't do anything when I click the [cmdFind] button. Can someone tell me what I'm doing wrong? Thanks in advance.
Code:
Public oRange As Object
Public myfindFirst As Boolean
Public intTextLength As Long
Private Sub cmdFind_Click()
Dim sSearch As String
Dim strText As String
Set oRange = WebBrowser0.Document.body.createTextRange
intTextLength = Len(oRange.Text)
If IsNull(Me.txtFind) Then
MsgBox "Please enter the text.", vbOKOnly + vbExclamation, "Missing Text or Word"
Exit Sub
End If
sSearch = txtFind.Text
Me.WebBrowser0.SetFocus
If oRange.FindText(sSearch, intTextLength) Then
oRange.SELECT
oRange.scrollIntoView
cmdFind.Caption = "Find Next"
Me.Refresh
Else
MsgBox ("Search string " & txtFind.Text & " not found.")
End If
Else
Me.WebBrowser0.SetFocus
Call oRange.Move("character")
Me.txtFind.SetFocus
sSearch = txtFind.Text
If oRange.FindText(sSearch, intTextLength) Then
Me.WebBrowser0.SetFocus
oRange.SELECT
oRange.scrollIntoView
Else
MsgBox ("Finished searching Document for string " & txtFind.Text)
cmdFind.Caption = "Find"
Me.Refresh
End If
End If