Saving Attachment to local drive

ardy

Registered User.
Local time
Today, 13:51
Joined
Sep 24, 2012
Messages
98
Hello All.

I have found the code below , It is function. I have managed to incorporate it to my form. The issue I am having is that I don't get any error, which is good, but I don't get the file saved either it seem nothing happens........ Can somebody hint me to the right direction......

My goal is to save the attachment (data type ) to a file in my local drive(project directory). the attachments could be anything, image, pdf, etc........

Any Help is Appreciated......
------ Attachment Data Type ---------
Attach
Attach.FileData
Attach.FileName
Attach.FileType
--------------------------------------------

Code:
Function SaveAttachment()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset2
    Dim rstAttachment As DAO.Recordset2
    Dim fld As DAO.Field2
    Dim strPath As String
    Dim intz As Integer
 
Set db = CurrentDb
        Set rst = db.OpenRecordset("Attachment", dbOpenDynaset)
            rst.FindFirst "ID = " & Forms!Attachment_NR!Lbl_AttachID
        Set rstAttachment = rst.Fields("Attach").Value
        Set fld = rstAttachment.Fields("Filedata")
            strPath = CurrentProject.Path & rstAttachment.Fields("Filename")
                On Error Resume Next
            Kill strPath
                On Error GoTo 0
 
            fld.SaveToFile strPath
 
    rstAttachment.Close
    rst.Close
        Set rstAttachment = Nothing
        Set rst = Nothing
        Set db = Nothing
 
End Function
 
Try it with the error code commented out.

Sent from my SM-G925F using Tapatalk
 
I get a Run-Time error '3839':
The specified file exists already......
The debug highlights fld.SaveToFile strPath :banghead:

OK... this is a bit confusing.... the strPath is pointing to CurrentProject.path......I checked and there is no such file at all.......so I don't understand what is it its looking at that makes it think there is file there already.........?????
 
Try MsgBox " >>> " & strPath

Sent from my SM-G925F using Tapatalk
 
Thanks......
Was missing a \
 

Users who are viewing this thread

Back
Top Bottom