Automating Web Form Input from VBA

Posted on 2009-02-23
Last Modified: 2012-06-27
Is there a current way of automating the input of a Web form from VBA from within Microsoft Access?

I don't have control of the Webform but have all the required data in an Access Database. I've searched for solutions and see one example but cannot get it to work. Perhaps I'm doing something wrong......This solution was from back in 2003.....Is there a better solution now??

As I've never done this before, so a working example would really be appreciated.

Don Garry
Sub Main()

'what is the page you want to pull up in your browser (ie

WebBrowser1.navigate ""

'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



Set doc = WebBrowser1.document    'access the document properties of the current page


Do While WebBrowser1.Busy



'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)



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


    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



 WebBrowser1.document.forms(0).elements(formtag).selectedIndex = Val(FillValue)


End If

End Function

Open in new window

Question by:DonGarry
    LVL 84
    The sample you give should work ... can you explain what you mean by "can't get it to work"? Do you get errors? If so, what errors? Or, does it seem to complete but doesn't work as expected?

    To see what's going on, set a breakpoint early in your code - in Design view, place your cursor somewhere at the start of the code and press F9 ... the code will highlight in Red. Now open the form in Normal view and execute whatever process you are testing. You'll be thrown into the VBA Editor, and you can step through the code (see the Debug menu).

    Accepted Solution

    Thanks for your quick reply....

    When I load that code into a module and start to step through Sub Main() I get a 'runtime error 424 object required' message on the first line...WebBrowser1.navigate ""

    I'm assuming the process starts at Sub Main.It looks to me that we would need to dimension and Set WebBrowser1 but I have no clue what that might look like......any suggestions?

    Don Garry

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now