Link to home
Start Free TrialLog in
Avatar of Eric Sherman
Eric ShermanFlag for United States of America

asked on

Using Access/VBA Function to Dowload a File from the Internet???

I am using the following VBA Function in Access 2010 to download a file from the Internet.  This Function will be used to distribute a new Access Front-End application connected to MySQL Back-End server.  

The problem with the code below is, once the file has been downloaded on the remote machine it will remain in cached.  Therefore, when the next update is published, it will now be downloaded.  It is being pulled from the Cached folder on the local machine.  A workaround is to add a unique id at the end of the file name like  "http://www.somedomain.com/appfolder/MyApp.accdbmm-dd-yyyy-hh-nn-ss" to make it unique each time.

My question ... Is there any modification to the code below that would force it to download the file from the url link instead of using the Cached folder on the local machine????


Public 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 DownloadFile()
On Error GoTo err_1

Dim lngPCallerParam As Long
Dim strURLParam As String
Dim strFilenameParam As String
Dim returnValue As Long

On Error GoTo err_1

    strURLParam = "http://www.somedomain.com/appfolder/MyApp.accdb"
    strFilenameParam = "C:\Temp\MyApp.accdb"
    returnValue = URLDownloadToFile(0, strURLParam, strFilenameParam, 0, 0)

Err_Exit:
    Exit Function
   
err_1:
    MsgBox Err.Description
    Resume Err_Exit

End Function


Thanks,

ET
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric Sherman

ASKER

Thanks IrogSinta ...  Your solution worked perfectly!!!

ET