[AccessD] Downloading Web File Automatically

Gustav Brock Gustav at cactus.dk
Wed Nov 14 15:53:54 CST 2012


Hi David

If you can reach the file via a URL, you can download it directly:

<code>
Option Compare Database
Option Explicit

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


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/conf2002/2002ConferencePicsbySmolin/images/dba02smolin27.jpg", "c:\happybassett.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".
' -2147467260 "transfer aborted".

' 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
</code>

/gustav


>>> newsgrps at dalyn.co.nz 14-11-12 21:40 >>>
Team,

 

I have an application that imports a csv file.  The file is put up onto a
web site url.  Entering the url in a browser will trigger downloading the
file.

 

Is there a way to automate this in Access.  Ie send the url to a browser,
have the file downloaded to a defined folder where it can then be imported?

 

Regards

David Emerson
Dalyn Software Ltd
Wellington, New Zealand




More information about the AccessD mailing list