UrlDownloadToFile in Access 2010 – Sub or Function not Defined

You’ll need to declare this WinAPI function in order to call it from 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

Leave a Comment