Solved

Using VB to fill in and submit an HTML form

Posted on 2004-04-21
8
1,103 Views
Last Modified: 2012-06-27
I am trying to create a login page for Hotmail but am getting "Run-time error 438 Object doesn't support this property or method". On the "IE.document.All.Item("XXX").Value" line's.
I have included Microsoft Internet Controls" in the References(also tried in components). And have tried with and without the HTML object Library.
When I look at MSDN http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/InternetExplorer.asp
It says it is read only??? Yet I have found several mentions to doing it this way on this and other sites????
This should be an easy question for someone but I am sure lost.
What am I missing? Thanks
Tom Jaeger

----------------------------------------------------------------------------------------------------

Option Explicit

Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument

Private Sub Form_Load()
Set IE = CreateObject("InternetExplorer.Application")
     IE.Navigate "www.hotmail.com"
     IE.Visible = True

End Sub


Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    'Url could change so take care of it ;)
    If InStr(1, URL, "login.passport.net/uilogin.srf?id=2", vbTextCompare) Then
            IE.document.All.Item("login").Value = "email"  'replace with your id
           
            IE.document.All.Item("passwd").Value = "pass"  'replace with your password
           
            IE.document.All.Item("submit1").Click
     End If
End If
End Sub
-----------------------------------------------------------------------------------------------------------
0
Comment
Question by:thomasjaeger
8 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10885077
The below uses no references or components. You can access the Form and it's elements directly as below. readystate 4 is "Complete".

Private Sub Form_Load()
    Dim oIE As Object, sURL As String
    sURL = "http://login.passport.net/uilogin.srf?id=2"
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Visible = True
    Call oIE.Navigate("www.hotmail.com")
    Do Until oIE.LocationURL = sURL And oIE.readystate = 4
        DoEvents
    Loop
    oIE.document.Form1.login.Value = "email@email.com"  'replace with your id
    oIE.document.Form1.passwd.Value = "pass"  'replace with your password
    oIE.document.Form1.submit1.Click
End Sub
0
 
LVL 14

Accepted Solution

by:
aelatik earned 50 total points
ID: 10886553
a minor change to you code makes it work.

Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument

Private Sub Form_Load()
Set IE = CreateObject("InternetExplorer.Application")
     IE.Navigate "www.hotmail.com"
     IE.Visible = True

End Sub


Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    If InStr(1, URL, "login.passport.net/uilogin.srf?id=2", vbTextCompare) Then
            IE.document.Form1.login.Value = "email"  'replace with your id
           
            IE.document.Form1.passwd.Value = "pass"  'replace with your password
           
            IE.document.Form1.submit1.Click
     End If
End If
End Sub
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10886558
Instead of IE.document.All.Item("login").Value

you use IE.document.Form1.login.value

This applies to other objects to..
0
 

Author Comment

by:thomasjaeger
ID: 10889606
Thanks Aelatik,
I am going to accept your answer... but I am stumped as to why there were refrences to the
IE.document.All.Item("login").Value = "email"  
all over the net when the correct way is
IE.document.Form1.login.Value = "email"


any thoughts?  Normally I wouldn't care but I am learning so I like to know what I did wrong and why.
Thanks
Tom J
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:aelatik
ID: 10891008
I really can't explain it. Sometimes it does work with IE.document.All.Item("login").Value = "email"
It depends on the website i guess. Try it on Google for example. Your method should work fine there...

Option Explicit

Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument

Private Sub Form_Load()
Set IE = CreateObject("InternetExplorer.Application")
     IE.navigate "www.google.com"
     IE.Visible = True
End Sub

Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If (pDisp Is IE) Then
        IE.document.All.Item("q").Value = "searchtext"
    End If
End Sub
0
 
LVL 5

Expert Comment

by:amit1978
ID: 10897168
looking for same
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10897300
>>  but I am stumped as to why there were refrences to the (etc etc)

There are multiple input-elements on the hotmail sign-in page with the names of "login" and "passwd" so you can't get one of the objects without specifying the form. You could have used to Forms collection within the document-element and then accessed the input-elements from that. The other method just accesses the elements directly.

Btw, my first comment showed the correct method to use. aelatik just double-posted it using your own example.
0
 
LVL 1

Expert Comment

by:vbplus
ID: 11050461
thomasjaeger,

The All array encompasses every element that has an id attribute, while the forms array is for 'in form' tags only, so if your form tag, such as <input type=...>, has an id then you can retrieve a reference to it via the all array.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

18 Experts available now in Live!

Get 1:1 Help Now