ardy
Registered User.
- Local time
- Today, 09:35
- 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
--------------------------------------------
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