SaveToFile Runtime Error -2147024891

mistera

Registered User.
Local time
Yesterday, 20:29
Joined
Jan 3, 2012
Messages
43
I'm running Access 2007 and have a table with several Excel file attachments (one attachment per record). Each record has a Type field to identify the various files. In VBA, I'm running a routine to save the Excel file to my hard drive. Here is an excerpt from my code:

Code:
    Set rs = db.OpenRecordset("SELECT * FROM tbl_Attachments WHERE [Type]='Header';")
    If rs.NoMatch Then
        MsgBox "The header file could not be found.  Please contact the database administrator." & vbNewLine & _
            vbNewLine & "Error occurred at: '" & strProc & ", " & strCodeLocn & "'.", vbCritical, "Critical Error"
        GoTo Exit_Prepare_Accruals
    End If
 
    Set rsChild = rs.Fields("Attachment").Value
    Set fldAttach = rsChild.Fields("FileData")
    strFilePath = "c:\jeupload.xlsx"
    If Len(Dir(strFilePath & "") & "") <> 0 Then
        Kill strFilePath
    End If
    fldAttach.SaveToFile strFilePath
    rsChild.Close
    rs.Close

This was working fine for several months. I don't know why all of a sudden I'm now getting a runtime error on the SaveToFile command. The error I'm getting is:

Error number: -2147024891
Error description: HRESULT: &H80070005

I have no idea what is going on and what is causing this error! I'm thinking this doesn't have anything to do with the Excel file itself, but must be something that changed in the environment.

Does anyone know what this error is and what could be causing it?
 
I figured out my issue! I realized that I started having this problem after my company upgraded my machine from Windows XP to Windows 7. After looking into changes with this upgrade, I learned that I no longer have permissions to save to the C:\ root directory. I just changed my code to save to another location and voila -- the code now works as it did before!
 

Users who are viewing this thread

Back
Top Bottom