UrlDownloadToFile in Access 2010 - Subfunction or function not defined

I am trying to use the URLDownloadToFile function in VBA Access 2010 code. When I run the code, it tells me that URLDownloadToFile is not defined.

I read that this function is in the urlmon.dll file that I have on my computer. I tried to click the links button in the code editor and load it, but this will not allow me to do this.

How can I fix this to use the function? Or is there another feature that will allow me to load the url into a file?

0
source share
1 answer

You will need to declare this WinAPI function to call it from the procedures in your code.

From HERE

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(URL As String, LocalFilename As String) As Boolean Dim lngRetVal As Long lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0) If lngRetVal = 0 Then If Dir(LocalFileName) <> vbNullString Then DownloadFile = True End If End If End Function Private Sub Form_Load() If Not DownloadFile("http://www.ex-designz.net", "c:\\photogallery.asp") Then MsgBox "Unable to download the file, or the source URL doesn't exist." End If End Sub 
+2
source

Source: https://habr.com/ru/post/1482296/


All Articles