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
LVL 19
Eric ShermanAccountant/DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IrogSintaCommented:
See if you can delete the file from the cache first.  Add this declaration to the top of your module where your function is.

Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias _
    "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long

Open in new window

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

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eric ShermanAccountant/DeveloperAuthor Commented:
Thanks IrogSinta ...  Your solution worked perfectly!!!

ET
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.