Link to home
Start Free TrialLog in
Avatar of hteel
hteelFlag for United States of America

asked on

Auto-populate a web form and click the command button

I need to write VB code that will populate a form on the web and click the command button.  Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of aelatik
aelatik
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hteel

ASKER

Thanks!  That is what I want, but I need just a little more help if you don't mind.  Below is your code modified to fit my situation.  I would like for IE to run in the background; therefore I assume I need to set IE.Visible to False.  I also would like to dump the html of the results (following the click of the command button) into a varriable.  

Private Sub Form_Load()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
 IE.Navigate "http://ssdi.genealogy.rootsweb.com/cgi-bin/ssdi.cgi"
 IE.Visible = True
 
  While IE.Busy
     DoEvents
 Wend
 
IE.Document.All("ssn").Value = "My Social Security Nbr" ' contains the HTML name of the object
IE.Document.All("submit").Click ' contains the HTML name of the object

End Sub

Place a textbox on your form with the mulitline property set on true and use the following code :

Private Sub Form_Load()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://ssdi.genealogy.rootsweb.com/cgi-bin/ssdi.cgi"
IE.Visible = True

  While IE.Busy
    DoEvents
Wend

IE.Document.All("ssn").Value = "My Social Security Nbr" ' contains the HTML name of the object
IE.Document.All("submit").Click ' contains the HTML name of the object

  While IE.Busy
    DoEvents
Wend

Str1 = IE.Document.body.innerhtml
  While IE.Busy
    DoEvents
Wend
Text1 = Str1

End Sub


Hope it works for you, i couldn't test it because the query doesn't return records.

Happy Programming,
Ayhan Elatik
aelatik, What does these two lines mean ? Would you please explain to me ?

IE.Document.All("ssn").Value = "My Social Security Nbr" ' contains the HTML name of the object
IE.Document.All("submit").Click ' contains the HTML name of the object


I would like to access the textfield in the form . Is it a way to locate the textfield in the form in the homepage ?
Yes, It will give the textfield named "ssn" the value "My social Security Nbr" and click on the button named "submit"
aelatik , would you please take a look on my question ? I think you must know how to answer it. The link is here :
https://www.experts-exchange.com/questions/20781860/Internet-Explorer-Object-and-Automation-and-Access-the-DOM-structure.html#9644691
Thanks.
Avatar of hteel

ASKER

aelatik,
I pulled a random SSN off of this site so that I could test and when I did it failed on the "IE.Document.All("submit").Click" line of code.  I got a run-time error 438  Object doesn't support this property or method.  

Below is your code with a legit SSN inserted.  Any advice why it fails?

Thanks!

Private Sub Form_Load()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://ssdi.genealogy.rootsweb.com/cgi-bin/ssdi.cgi"
IE.Visible = True

  While IE.Busy
    DoEvents
Wend

IE.Document.All("ssn").Value = "450875872" ' contains the HTML name of the object
IE.Document.All("submit").Click ' contains the HTML name of the object

  While IE.Busy
    DoEvents
Wend

Str1 = IE.Document.body.innerhtml
  While IE.Busy
    DoEvents
Wend
Text1 = Str1

End Sub
Hteel,

I don't know what has gone wrong but a copyied the code and it works with me...
"IE.Document.All("submit").Click" can only cause problems if it doesn't exist in the HTML document or woth a different name. Beware that "IE.Document.All("submit").Click", submit is the name of the button.
Avatar of hteel

ASKER

hmmm.....thanks for responding....at least I know it's not something wrong with the code if it is working for you....must be something wrong with my version of VB....thanks again!