SaveToFile Runtime Error -2147024891

mistera

Board Regular
Joined
May 6, 2008
Messages
54
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

Everything has been working with this for several months. In fact, it worked yesterday. However, today, I'm 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?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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!
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top