Johnydev
Johnydev

Reputation: 21

The system cannot locate the resource specified for MS Access vba Download file from link

In MS Access VBA , I want to download file from link on internet ,

in Windows 10 x64 these functions work correctly with no error, but it encounters an error in Window 7 x64

in the below code on objXMLHTTP.send I get this error :

Run-time error '-2146697211 (800c0005)': The system cannot locate the resource specified

Sub DownloadFile(URL As String, LocalFile As String)
    Dim objXMLHTTP As Object
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    objXMLHTTP.Open "GET", URL, False
    objXMLHTTP.send

    If objXMLHTTP.Status = 200 Then
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
        objADOStream.Type = 1 'adTypeBinary

        objADOStream.Write objXMLHTTP.ResponseBody
        objADOStream.SaveToFile LocalFile, 2 'adSaveCreateOverWrite
        objADOStream.Close
        Set objADOStream = Nothing
    End If

    Set objXMLHTTP = Nothing
End Sub

Private Sub Form_Open(Cancel As Integer)
Call DownloadFile("https://ghaemcoarsh.com/APPY/BMH.exe", "C:\Users\Administrator\Desktop\test\BMH.exe")
End Sub

the point is my code works on Windows 10 but it only error on Windows 7

Upvotes: 2

Views: 674

Answers (0)

Related Questions