Download CSV file via URL in Access 2003

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!
Who is Participating?
Gustav BrockConnect With a Mentor CIOCommented:
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

ryanvb83Author Commented:
This was perfect.  Thank you!
Gustav BrockCIOCommented:
You are welcome!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.