PDA

View Full Version : Fill Existing Webpage Fields With Data



CreganTur
08-08-2008, 09:38 AM
I've got a program I've created to automate a process here at work. One of the tasks I want to automate is for data from an Access Form to automatically populate to textfields in a webpage on Internet Explorer.

I can do this by bringing up a new webpage with this:

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://zip4.usps.com/zip4/welcome.jsp"
IE.Visible = True
While IE.busy
DoEvents
Wend
IE.Document.all("address2").Value = "123 Carraige Way"
IE.Document.all("city").Value = "Shreveport"
IE.Document.all("State").Value = "CA"
IE.Document.all("zip5").Value = "90210"

If you run this code, you'll see that it works perfectly.

My issue is that I need to populate text to an already exisitng webpage- one that's already open in internet explorer. This is due to the fact that the webpage I need to work with can only be accessed after a user logs into the website, and for security reasons I am not going to automate the login procedure.

What do I need to adjust so that I can get the above code to focus on an existing page?

CreganTur
08-08-2008, 12:10 PM
Someone at work helped me figure this one out. Here's the code that will interact with an already opened webpage, and will load data into textboxes on the page.

Here's the code (Requires a reference to Microsoft Internet Controls):

Dim ieDoc As Object
Dim sws As SHDocVw.ShellWindows
Dim strURL As String
Dim n As Integer
'Set main URL to evaluate open IE windows
strURL = "http://zip4.usps.com/zip4/welcome.jsp"
Set sws = New SHDocVw.ShellWindows
'Cycle through all open IE windows and assign the window whose URL matches strURL
For n = 0 To sws.Count - 1
If Left(sws.Item(n).LocationURL, Len(strURL)) = strURL Then
Set ieDoc = sws.Item(n).Document
sws.Item(n).Visible = True
Exit For
End If
Next n
ieDoc.all("address2").Value = "123 Carraige Way"
ieDoc.all("city").Value = "Shreveport"
ieDoc.all("State").Value = "CA"
ieDoc.all("zip5").Value = "90210"

But, if someone wants to show another way to accomplish this, please do!

stanl
08-11-2008, 04:57 AM
outside the fact you should probably code for the possibility that the ie window is not opened, you seem to have it. If the url were launched by you/VBA ie has an hwnd property so you could use GetObject().

I'm assuming the url has a submit button and the data input from Access has a return value in which case you could also use 'HTTP Post'.

.02 Stan

[edit]
P.S. - just noticed you State Flag - I'm in Raleigh

CreganTur
08-11-2008, 05:17 AM
VBA ie has an hwnd property so you could use GetObject().
Would the window's handle (hwnd) be the parameter for GetObject()? Would it be evaluated as a string or as number?


you could also use 'HTTP Post'
I'm unfamiliar with this- any links you could share?


P.S. - just noticed you State Flag - I'm in Raleigh
I'm in Greensboro- small world after all :)

stanl
08-11-2008, 06:00 AM
here is a start

http://www.mombu.com/microsoft/internet-explorer-scripting/t-how-to-capture-a-specific-ie-window-idhandle-with-vba-269443.html

but it really depends on how expansive your app is, and GetObject() is quite finicky with IE. I wrote an app for the NC Saves SignUp website (which had 14 text and 5 dropdowns). The 'users' never even saw the website. They were small non-profits or Cooperative Extension offices (who didn't even have Microsoft Office). The data was input to a form and saved to an Access Table, using only ADO and fabricated recordsets. Then an Internet connection was checked/detected, a hidden instance of IE was launched and credentials sent, then HTTP Post used to upload data just entered from form. [sorry for the Tangent]

CreganTur
08-11-2008, 06:27 AM
Thanks man.

Hey, do you have any idea how to fill in cells in a javascript table? I'm hoping it can be done in a way similar to what I'm doing with filling in the textboxes... because I REALLY don't want to use sendkeys.

stanl
08-11-2008, 07:57 AM
Thanks man.

Hey, do you have any idea how to fill in cells in a javascript table? I'm hoping it can be done in a way similar to what I'm doing with filling in the textboxes... because I REALLY don't want to use sendkeys.

define 'javascript table' - some backend databases employ java 'grids'; other use pop-up child windows which cannot be handled directly by DHTML, but in a previous thread where I was assisted by Tom Schreiner you can use IE events to get at it.

In situations like these, hopefully someone from the community reading this can suggest an open url we can use to test code with.

Stan

CreganTur
08-11-2008, 08:03 AM
define 'javascript table'

Well... first of all I know next to nothing about Java. It may be a Grid. It uses the keyword 'GridProps' in the section where the text of the of the row headers is setup.

stanl
08-11-2008, 03:32 PM
Hard to say, I guess. I deal with a Java Grid on a daily basis, the backend is Cold Fusion, so parsing it involves a whole lot of transforming escape codes. What you can do is save the page locally as an .htm file. I have a freeware compiled exe called IEAnal that extracts DHTML elements and writes code snippets for them.

CreganTur
08-12-2008, 05:27 AM
I have a freeware compiled exe called IEAnal that extracts DHTML elements and writes code snippets for them.
Can you please provide a link for this program?

NinjaEdithttp://img293.imageshack.us/img293/9060/ninja3od8.gif: I found your website via Google (and googling 'IEAnal' brings up some interesting results:bug:

I really hope this will help me be able to work with this webpage.

stanl
08-12-2008, 03:22 PM
and googling 'IEAnal' brings up some interesting results:bug:


OMG... did you check out the IEAnalRetentive stuff?

CreganTur
08-13-2008, 05:29 AM
OMG... did you check out the IEAnalRetentive stuff?
I'm afraid of what would come up:SHOCKED:

I'm starting to wonder if my problems stem from some unusual design on the webpage I'm trying to work with. Either it's using non-standard objects... or I'm just clueless about how to interact with them. Probably the second one:whistle: