Download CSV file via URL in Access 2003

Posted on 2008-06-16
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!
Question by:ryanvb83
  • 2
LVL 49

Accepted Solution

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.

' 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("", "c:\dbaheaderkey.jpg")


' Usage, download a page:

' lngRet = DownloadFile("", "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


Author Closing Comment

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

Expert Comment

by:Gustav Brock
ID: 21812938
You are welcome!


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

895 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

12 Experts available now in Live!

Get 1:1 Help Now