Link to home
Create AccountLog in
Avatar of newbie46
newbie46

asked on

Overwriting file when saving Attachment to a Folder

I am using the following code to save an attachment to a folder:

set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

if fDialog.Show = True then
  strPath = fDialog.SelectedItems (1)
end if

select AttachedDocument
from tblA

set rst - db.OpenRecordset (strSQL, dbOpenDynaset)
if Not (rst.bof and rst.eof) then
  do while not rst.eof

    set rst2 = rst.fields("AttachedDocument").Value
    rst2.openRecordset

    rst2.Fields ("FileData").SaveToFile (strPath)

If the same named file already exists in the selected folder, an error is returned. Is it possible to overwrite the file existing within the selected folder with the attachment being saved?
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of newbie46
newbie46

ASKER

Thank you. That worked!