Link to home
Create AccountLog in
Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Avatar of DonGarry
DonGarry

How to use the ActiveX Microsoft WebBrowser Control
I've got the follow code working just fine as long as I'm just filling in one control on the webpage. My question is how would I revise the code below to fill in multiple web input controls plus how would I programmatically fire an on_click event using VBA for Access?
Sub Main()
Dim WebBrowser1 As HTMLObjectElement
 
'what is the page you want to pull up in your browser (ie icq.com/sms)
WebBrowser1.navigate "http://www.google.com"
 
 
'sometimes there are timing issues, so issue a couple of doevents so the browser responds
DoEvents: DoEvents: DoEvents
 
Do While WebBrowser1.Busy   'wait until the page loads by looping
  DoEvents
Loop
 
 
Set doc = WebBrowser1.Document    'access the document properties of the current page
DoEvents
 
Do While WebBrowser1.Busy
DoEvents
Loop
 
'if you pull your page up in IE and you view the source,
'you can find the form variables that you want to fill in
'I'm sure there are other ways to iterate through the form
' to get them, but I never could figure it out.
 
returnValue = FillForm("q", "this is my search criteria", False)
 
WebBrowser1.Document.Forms(0).submit
 
 
End Sub
 
 
Public Sub ClickLink(doc, LinkText As String)
For i = 0 To doc.links.length - 1
   If InStr(LTrim(RTrim(doc.links(i).outerText)), LinkText) > 0 Then
    doc.links(i).Click
    Exit For
  End If
Next i
End Sub
 
 
Function FillForm(ByVal formtag, ByVal FillValue, ByVal isCombo As Boolean) As Boolean
Dim elemcollection As IHTMLElementCollection
Dim obj As Object
Dim element2 As HTMLInputElement
Dim element As HTMLInputElement
 
 
If Not isCombo Then
 
 WebBrowser1.Document.Forms(0).elements(formtag).Value = FillValue
 
Else
 WebBrowser1.Document.Forms(0).elements(formtag).selectedIndex = Val(FillValue)
 
End If
 
 
End Function

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Scott McDaniel (EE MVE )Scott McDaniel (EE MVE )🇺🇸

Your function below seems to be the one that fills in your values. It specifically references a control named "WebBrowser1", which is your web broswer control (at least I'd hope it is <g>).

Function FillForm(ByVal formtag, ByVal FillValue, ByVal isCombo As Boolean) As Boolean
  Dim elemcollection As IHTMLElementCollection
  Dim obj As Object
  Dim element2 As HTMLInputElement
  Dim element As HTMLInputElement
 
If Not isCombo Then
  WebBrowser1.Document.Forms(0).elements(formtag).Value = FillValue
 Else
 WebBrowser1.Document.Forms(0).elements(formtag).selectedIndex = Val(FillValue)
 End If
 
End Function

If you wanted to fill another document in a different webrowser control, you'd just reference that control in your If Not isCombo block:

  WebBrowser2.Document.Forms ect ect

But I suspect there's more to it than this ... can you explain a bit more as to what you want to do?

Avatar of DonGarryDonGarry

ASKER

You are correct, I have a WebBrowser1 Control and the exisitng code fills in ONLY one input box called 'q'. My question is how would I change our code to fill in two more input boxes say 'username'  & 'password' and then click the 'submit' button in the WebBrowser1 Control?

ASKER CERTIFIED SOLUTION
Avatar of DonGarryDonGarry

ASKER

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.