[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Automating Web Form Input from VBA

Posted on 2009-02-23
2
Medium Priority
?
1,148 Views
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.

Thx
Don Garry
Sub Main()
 
'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

0
Comment
Question by:DonGarry
2 Comments
 
LVL 85
ID: 23720764
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).
0
 

Accepted Solution

by:
DonGarry earned 0 total points
ID: 23721984
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 "http://www.google.com"

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?

Regards,
Don Garry
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

834 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