VBA Webpage search

Fyte101

New member
Local time
Today, 07:36
Joined
Oct 30, 2024
Messages
2
Thank you in advance for any help given. I am trying to open an intranet page and then search on that page for information which is contained in a text box (txtMan) on a form.
Issue: The search is not happening on the opened webpage but on the MS Access form and any "setfocus" line is not working. Also I can not figure out how to return a message if text is found versus text not found.

Private Sub cmdSearch_Click()

On Error GoTo Error_cmdSearch

Dim strHyperlink As String

strHyperlink = Me.hypSearch
Application.FollowHyperlink strHyperlink, , True

If Len(Me.txtMan.Value & vbNullString) > 0 Then

SendKeys "^f", False
SendKeys Me.txtMan.Value, False
SendKeys "{ENTER}", False
SendKeys "{ESC}", False

End If

''**************************************************
' If statement based on returned value from search
' If true
' MsgBox "Text found on the website"
'Else
'MsgBox "Text not found on the website"
'End IF
''**************************************************

Exit_cmdSearch:
Exit Sub

Error_cmdSearch:
MsgBox Err & ": " & Err.Description
Resume Exit_cmdSearch

End Sub
 
Hi. Welcome to AWF!

Perhaps it would be better to avoid using SendKeys and perhaps use an HTTPRequest class object instead.
 
OK so I am back to trying to make this work... maybe I am going at this wrong so I will just ask is it even possible to perform the following action in MS Access
Here is the psuedo-code of what I want the function to do
1 On Click -- User clicks a button on a form

2 If 2 data sets exist then it will run the function
2.1 Text Box 1 (String)
2.2 Internal database table mapping to an intra-net webpage

3 Function
3.1 Open webpage
3.2 Lookup on the webpage the information 2.1
3.3 If a perfect match is found then
MsgBox "Text Box 1 Found"
Else
MsgBox "Text Box 1 Not Found"
End If

Notes: I have tried using several code formats but I get close but cannot make it work correctly.
 
Like I said, one way to read a webpage is to use the HTTPRequest class. Here's an example:
Code:
Public Function SearchWebpage(TextToSearch As String) As Boolean
'thedbguy@gmail.com
'1/24/2025

Dim oHTTP As Object
Dim strURL As String
Dim strWebpage As String
Dim blnResult As Boolean

strURL = "https://thedbguy.blogspot.com"

Set oHTTP = CreateObject("Microsoft.XMLHTTP")
With oHTTP
    .Open "GET", strURL, False
    .send
    If .Status = 200 Then
        strWebpage = .responseText
    End If
End With

If strWebpage <> "" Then
    blnResult = strWebpage Like "*" & TextToSearch & "*"
End If

SearchWebpage = blnResult

Set oHTTP = Nothing

End Function
 

Users who are viewing this thread

Back
Top Bottom