Solved

Download CSV file via URL in Access 2003

Posted on 2008-06-16
3
431 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

825 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