Results 1 to 4 of 4
  1. #1
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67

    UnResolveable 3004 runtime error - Write to file failed

    I have the following code which issues a 3004 runtime error on ostream.SaveToFile.

    Private Sub cmdDownLoad_Click()

    Dim myURL As String
    myURL = "https://mysharepointURL/BWQprd.xlsx"



    Dim WinHttpReq As Object, oStream As Object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    With WinHttpReq
    WinHttpReq.Open "GET", myURL, False
    WinHttpReq.Send

    If WinHttpReq.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.responseBody
    oStream.SaveToFile "c:\BWQprd.xlsx", 1 ' 1 = no overwrite, 2 = overwrite
    oStream.Close
    End If
    End With
    End Sub

    Thoughts!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    did you copy that from here https://stackoverflow.com/questions/...68766#48968766
    looks similar, but not exact. If you're going to use a With block, don't repeat the object variable name:

    With WinHttpReq
    .Open "GET", myURL, False
    .Send

    Make sure you have permissions on the directory and that it does in fact exist?
    Please enclose code in code tags (# button on posting toolbar) for more than a few lines.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Dave_D's Avatar
    Dave_D is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    67
    Thank you for your reply and as a matter of fact, I did copy that from https://stack.... I also removed the WITH block. When I paste the URL of the one which I'm using into my browser, it takes me directly to that file in sharepoint online, so I'm assuming I have permissions, if this is the permissions you are referring to.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I had the destination folder in mind but can see how it could be an issue both ways. Have never done this so likely won't be of much help. One thing I might do is step through the code and in the immediate window test for any known properties for oStream object (perhaps when you reach .Write line). However I have no idea what property to suggest. Can say though that when testing like this I often type my reference (preceded by question mark of course) and use .Name even if I know the name. If I raise an error, there is something wrong with the reference (e.g. the object may not exist, be loaded or I just plain have the reference wrong).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error -3004 in Form with subform
    By rcrobman in forum Forms
    Replies: 6
    Last Post: 11-17-2018, 10:43 AM
  2. Replies: 1
    Last Post: 09-17-2015, 10:04 PM
  3. runtime error 3157 odbc update on a linked table failed
    By KAMALRAJ.PPS in forum Programming
    Replies: 2
    Last Post: 12-02-2014, 09:43 AM
  4. Replies: 3
    Last Post: 09-18-2014, 12:24 PM
  5. Runtime error 1004 - Save method of workbook failed
    By captdkl02 in forum Programming
    Replies: 2
    Last Post: 01-03-2013, 05:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums