Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2562
  • Last Modified:

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
0
Eric Sherman
Asked:
Eric Sherman
1 Solution
 
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

0
 
Eric ShermanAccountant/DeveloperAuthor Commented:
Thanks IrogSinta ...  Your solution worked perfectly!!!

ET
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now