• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

Using VB to enter data on a Web Form

I have a website that I go to every morning to gather data.  I want to use Visual Basic to gather the data automatically but I first have to fill in a form of what data to extract (date, report, etc...)  Is there a code to automatically fill in a form automatically.  I was going to try a bunch of "SendKeys" but it seems to be the long way and it's not working.

HELP please.!!!

Thx, AJ
0
ajpelkey
Asked:
ajpelkey
  • 4
  • 3
  • 3
  • +4
6 Solutions
 
Richie_SimonettiIT OperationsCommented:
www.angelfire.com/realm/vb-shared/index.html under ie topic (example for Hotmail)
0
 
Richie_SimonettiIT OperationsCommented:
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fantasy1001Commented:
Ok, here is an example of filling the google form

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "http://www.google.com"
    IE.Visible = True
    Do While IE.Busy
       DoEvents
    Loop

IE.Document.All("username").Value = "so hard"
IE.Document.All("password").Value = "visual basic"
Ie.DOcument.All("submit").Click   'this will click the button

Description:
First you open the ie object, then we can get to the control inside the form with ie.document.all("controlname").value/click

~ fantasy ~
0
 
JackOfPHCommented:
Listening....

:-)
0
 
fantasy1001Commented:
Sorry, sorry, wrong syntax
Let assume the Google is the place where you upload. you can use this

Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "http://www.google.com"
    IE.Visible = True
    Do While IE.Busy
       DoEvents
    Loop

IE.Document.All("q").Value = "so hard"
Ie.DOcument.All("btnG").Click   'this will click the button

Try to experience and find the q and btnG control name with FrontPage.

~ fantasy ~
0
 
ajpelkeyAuthor Commented:
ok, ALL the above answers helped me out a TON, but let's take it to the next level.  I have a list box that has about 20 items.  I want to select them all.  The list box is named "as_tks_projects".  The list box is set as follows: <SELECT NAME="as_tks_projects" SIZE="3"  multiple>

If I use the following command: IE.Document.All("as_tks_projects").Value = "BBC1" it selects the single item.

If I use the following command: IE.Document.All("as_tks_projects").click it selects the first item.

I want to know how to select all items.

Thx,
AJ
0
 
monvelasquezCommented:
Try this

Dim i as integer
For i = 0 to IE.Document.All("as_tks_projects").options.length-1
      IE.Document.All("as_tks_projects").options(i).selected = True
Next

____________
Raymond:\>_
0
 
fantasy1001Commented:
I think Raymond has give you the direction on doing that,
the .Value will return the object in select
the .Click is a method to click on the submit button

~ fantasy ~
0
 
ajpelkeyAuthor Commented:
ok, I am gonna share the wealth on this one because all the answers are awesome.  I need one more help.  The last website I am taken to is a place to download a file.  The file is a link.  The link is as follows: /web01/user_reports/AJP915??.psr where the question mark is a variable.  How can I identify the file, and open the file (or download but prefer just to open).
0
 
Dang123Commented:
This should help you identify the file

Public Function GetHTMLCode(URL As String)
Dim IE As Object
Dim i As Long

Set IE = CreateObject("InternetExplorer.Application")
  IE.Navigate URL
  While IE.Busy
      DoEvents
  Wend
  For i = 0 To IE.Document.All.length - 1
      If IE.Document.All(i).Tagname = "A" Then
          If InStr(IE.Document.All(i).href, ".psr") > 0 Then
            MsgBox IE.Document.All(i).href
          End If
      End If
  Next
End Function
0
 
Richie_SimonettiIT OperationsCommented:
just a little modification:

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

'example by Matthew Gates (Puff0rz@hotmail.com)

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function
Public Function GetHTMLCode(URL As String)
Dim IE As Object
Dim i As Long

Set IE = CreateObject("InternetExplorer.Application")
  IE.Navigate URL
  While IE.Busy
      DoEvents
  Wend
  For i = 0 To IE.Document.All.length - 1
      If IE.Document.All(i).Tagname = "A" Then
          If InStr(IE.Document.All(i).href, ".psr") > 0 Then
            DownloadFile IE.Document.All(i).href, "c:\mydownloadedfile.htm"

          End If
      End If
  Next
End Function
 
0
 
ajpelkeyAuthor Commented:
Everyone,
You did it.  You got me from start to finish on this code.  Big thx goes to fantasy1001 because he had me going in the right direction.  I ended up running into more roadblocks on the way and the thx go out to the rest of the Assisted Answers.

I have asked my boss if I can add you all to our payroll but unfortunately the economy hinders us.

Thx to all,
AJ
0
 
aftab2003Commented:
If I just want to click on a link that is on a web page conatining mamy links, how do I do that ?:

<a href="http://www.cnn.com/index.html">CNN</a>

I tried this:
For i = 0 To IE.document.All.length - 1
   If IE.document.All(i).tagName = "A" Then
     If InStr(IE.document.All(i).href, ".htm") > 0 Then
      'IE.document.All(i).href.Click ' this is the ???question :-) it does not work
      MsgBox IE.document.All(i).href
     End If
    End If
 Next


Thanks
Aftab
0
 
aftab2003Commented:
This works

For i = 0 To IE.document.All.length - 1
   If IE.document.All(i).tagName = "A" Then
     If InStr(IE.document.All(i).href, "cnn.com") > 0 Then
      'DownloadFile IE.document.All(i).href, "c:\mydownloadedfile.htm"
      'IE.document.All(i).href.Click
      MsgBox IE.document.All(i).href
      'MsgBox i
      IE.navigate IE.document.All(i).href
     End If
    End If
 Next

Aftab
0
 
Richie_SimonettiIT OperationsCommented:
If problem is links in a web page, there is a links collection that we can use to iterate throught all link on a given page.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now