PDA

View Full Version : Data input into Internet Form with Frames



enrique63
10-20-2011, 12:23 PM
How do I modify the code below so that I can input data into an internet form? The internet form seems to have frames, which I'm not familar with. Unfortunately, the internet page is internal, but I've attached the source code for your reference.

The webpage has 3 frames, each with an input, but at this point, I'm just trying to input "143709" into the first input field. Any help would be appreciated, even a working example to help me adapt my code would be great!


Sub ePAF()
Dim i As Long
Dim objIE As Object
Dim objElement As Object
Dim objCollection As Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "https://www03/ePAF/PAF.aspx?Mode=New"
Do While objIE.Busy
DoEvents
Loop

Set objCollection = objIE.Document.forms(1).all("aspnetForm").getelementsbytagname("input")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "ctl00$ContentPlaceHolder1$txtEmpSearch" Then
objCollection(i).Value = "143709"
End If

If objCollection(i).Type = "submit" And objCollection(i).Name = "ctl00$ContentPlaceHolder1$btnMultPositions" Then
Set objElement = objCollection(i)
objElement.Click ' click button to submit
End If

i = i + 1
Wend
Set objIE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub

enrique63
10-20-2011, 03:36 PM
I made a small discovery! Using the code below:
Set objCollection = objIE.document.all("ctl00$ContentPlaceHolder1$txtEmpSearch")
objCollection.Value = "116127"

I was able to populate the text field SOMETIMES, as it doesn't always work for some reason. Perhaps using the document.frame property (instead of document.all) would be more specific making the code work more consistently???

Below is the complete code:
Sub ePAF()
Dim i As Long
Dim objIE As Object
Dim objElement As Object
Dim objCollection As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "https://www03/ePAF/PAF.aspx?Mode=New"

Do While objIE.Busy
DoEvents
Loop

Set objCollection = objIE.document.all("ctl00$ContentPlaceHolder1$txtEmpSearch")
objCollection.Value = "116127"

Set objIE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub

enrique63
10-21-2011, 09:44 AM
OK, so it turns out that it's not necceary to use the document.frames property because I can consistently input data using the document.getelementsbytagname("input"). Below is the working code.

Of course, now I have a new problem, but I think it'll be better to post it in a separate thread.

Sub ePAF()
'Adapted from http://www.excely.com/excel-vba/ie-automation.shtml

Dim i As Long
Dim objIE As Object
Dim objElement As Object
Dim objCollection As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.navigate "https://www03/ePAF/PAF.aspx?Mode=New"
Do While objIE.Busy
DoEvents
Loop

Set objCollection = objIE.document.getelementsbytagname("input")
i = 0
While i < objCollection.Length
If objCollection(i).Name = "ctl00$ContentPlaceHolder1$txtEmpSearch" Then
objCollection(i).Value = "143709"

Else
If objCollection(i).Type = "submit" And objCollection(i).Name = "ctl00$ContentPlaceHolder1$btnSearchEmployee" Then
Set objElement = objCollection(i) ' "Search" button is found
End If
End If
i = i + 1
Wend
'objElement.Click ' click button to search

' Wait while IE re-loading...
Do While objIE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

' Clean up
Set objIE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub