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

Posted on 2012-08-20
Last Modified: 2013-11-19
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  "" 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 = ""
    strFilenameParam = "C:\Temp\MyApp.accdb"
    returnValue = URLDownloadToFile(0, strURLParam, strFilenameParam, 0, 0)

    Exit Function
    MsgBox Err.Description
    Resume Err_Exit

End Function


Question by:Eric Sherman
    LVL 29

    Accepted Solution

    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 = ""
        strFilenameParam = "C:\Temp\MyApp.accdb"
        DeleteUrlCacheEntry strURLParam 
        returnValue = URLDownloadToFile(0, strURLParam, strFilenameParam, 0, 0)

    Open in new window

    LVL 19

    Author Comment

    by:Eric Sherman
    Thanks IrogSinta ...  Your solution worked perfectly!!!


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Several part series to implement Internet Explorer 11 Enterprise Mode
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
    This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now