Solved

Download CSV file via URL in Access 2003

Posted on 2008-06-16
3
411 Views
Last Modified: 2013-12-18
I'm looking for a simple way to download a CSV file via URL in VBA code.  A portion of the URL will have to be dynamic and based on the user input into a textbox on the form.  Thanks in advance for the help!
0
Comment
Question by:ryanvb83
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 21797616
You should be able to modify this function take a parameter for the portion of the URL.

/gustav
' Declarations.

 

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

 

' Function to retrieve file.

 

Public Function DownloadFile( _

  ByVal strURL As String, _

  ByVal strLocalFilename As String) _

  As Long

  

' Download file or page with public access from the web.

' 2004-12-17. Cactus Data ApS, CPH.

 

' Usage, download a file:

' lngRet = DownloadFile("http://www.databaseadvisors.com/Graphics/Header/key.jpg", "c:\dbaheaderkey.jpg")

'

' Usage, download a page:

' lngRet = DownloadFile("http://www.databaseadvisors.com/conf2002/conf200202.htm", "c:\dbaconference.htm")

 

' Returns 0 if success, error code if not.

' Error codes:

' -2146697210 "file not found".

' -2146697211 "domain not found".

 

' Limitation.

' Does not check if local file was created successfully.

 

  Dim lngRetVal As Long

    

  lngRetVal = URLDownloadToFile(0, strURL & vbNullChar, strLocalFilename & vbNullChar, 0, 0)

  

  DownloadFile = lngRetVal

  

End Function

Open in new window

0
 

Author Closing Comment

by:ryanvb83
ID: 31467763
This was perfect.  Thank you!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 21812938
You are welcome!

/gustav
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

758 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

20 Experts available now in Live!

Get 1:1 Help Now