UrlDownloadToFile in Access 2010 - Sub or Function not Defined

前端 未结 1 1269
旧巷少年郎
旧巷少年郎 2020-12-02 01:15

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

I have read that th

相关标签:
1条回答
  • 2020-12-02 02:05

    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
    
    0 讨论(0)
提交回复
热议问题