Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download txt file from website URL

Status
Not open for further replies.

TKaminski

Programmer
Sep 5, 2001
27
US
I am looking for help on how to use VBA code behind a form in MS Access 2000 to:

1) Connect to a websites URL,
example: "
2) Pass a string to the webpage to populate a text box.
example: "IBM".

3) "Click" on a button on the webpage.
example: The "download" button.

4) Name the file:
example: "IBM_DataFile.txt"

5) Save the file to a stated folder on my PC.
example: "c:\data\Monday\"

Here is the code I have so far.

Code:
Private Sub cmdDownLoad_Click()

Dim FileAvailable As String

FileAvailable = funDownloadFile("[URL unfurl="true"]http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx",[/URL] "C:\data\Monday\IBM_DataFile.txt")

    If FileAvailable = False Then 'No connection or file not found
         MsgBox "File not found!"
    Else
         MsgBox "File successfully downloaded"
    End If

End Sub

'-----------
'-----------

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
Private Const ERROR_SUCCESS As Long = 0

'-----------

Public Function funDownloadFile(sSourceUrl As String, _
                             sLocalFile As String) As Boolean
  
  'if the API returns ERROR_SUCCESS (0),
  'return True from the function
   funDownloadFile = URLDownloadToFile(0&, _
                                    sSourceUrl, _
                                    sLocalFile, _
                                    0&, _
                                    0&) = ERROR_SUCCESS
   
End Function

I did not write this code. It is a code sample from one of the many great posting here. I am pretty good at building frm, qry and rpts, but I am in over my head here and the help files are leaving me in circles.

The msgbox reports that the txt file downloaded, but no such luck. The path in the code is typed correct and the their is no copy of a file with that name to worry about over writting.

I'm not sure if I need to use the SendKeys method or find a way to interact with the HTML? SendKeys is such an "iffy" way of coding.

I am using IE as my browser, if it matters.

I know to some, this looks easy, but it is a new area for.

Thank you for sharing your time and talent.
 
Have you read the following from this site ?
PLEASE NOTE: IT IS STRICTLY PROHIBITED TO DOWNLOAD DELAYED QUOTE TABLE DATA FROM THIS WEB SITE BY USING AUTO-EXTRACTION PROGRAMS/QUERIES AND/OR SOFTWARE. CBOE WILL BLOCK IP ADDRESSES OF ALL PARTIES WHO ATTEMPT TO DO SO. THIS DATA IS PROPERTY OF THOMSON FINANCIAL/ILX. DOWNLOADING THIS DATA IN ANY OTHER WAY THAN BY MANUAL TICKER SYMBOL ENTRY IS STRICTLY PROHIBITED.
 
Bad example of a URL.

Please feel free to use the Yahoo version. My error in posting that URL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top