Solved

Using VB to enter data on a Web Form

Posted on 2003-11-03
16
488 Views
Last Modified: 2010-05-01
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
Comment
Question by:ajpelkey
  • 4
  • 3
  • 3
  • +4
16 Comments
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 125 total points
ID: 9673682
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9673979
www.angelfire.com/realm/vb-shared/index.html under ie topic (example for Hotmail)
0
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 125 total points
ID: 9674054
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 150 total points
ID: 9675615
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
 
LVL 15

Expert Comment

by:JackOfPH
ID: 9675723
Listening....

:-)
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9676048
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
 

Author Comment

by:ajpelkey
ID: 9676190
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
 
LVL 3

Assisted Solution

by:monvelasquez
monvelasquez earned 100 total points
ID: 9676327
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:fantasy1001
ID: 9676456
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
 

Author Comment

by:ajpelkey
ID: 9681053
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
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 125 total points
ID: 9681181
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
 
LVL 16

Assisted Solution

by:Richie_Simonetti
Richie_Simonetti earned 125 total points
ID: 9681361
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
 

Author Comment

by:ajpelkey
ID: 9681654
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
 

Expert Comment

by:aftab2003
ID: 9683927
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
 

Expert Comment

by:aftab2003
ID: 9684086
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9686764
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

16 Experts available now in Live!

Get 1:1 Help Now