Retrieve the file

Hi,
I have the relevant picture file stored in the Access 2013 table. what is the way/query to retrieve the picture file inside that?
LVL 11
HuaMinChenSystem managerAsked:
Who is Participating?
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:
If you have images store in the new attachment data type this here is an example:

Saving an Internal Attachment Back to a File
On Error GoTo Err_SaveImage

Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2

Set db = CurrentDb
Set rsParent = Me.Recordset

rsParent.OpenRecordset

Set rsChild = rsParent.Fields("AttachmentTest").Value

rsChild.OpenRecordset
rsChild.Fields("FileData").SaveToFile ("c:\")

Exit_SaveImage:

Set rsChild = Nothing
Set rsParent = Nothing
Exit Sub

Err_SaveImage:

If Err = 3839 Then
MsgBox ("File Already Exists in the Directory!")
Resume Next

Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_SaveImage

End If

Open in new window

0
 
als315Commented:
If you have path to image in table, you can use method from my article:
Images on continuous forms
0
 
HuaMinChenSystem managerAuthor Commented:
Sorry, there are already images stored in the table but I want to retrieve the file from the table.
0
 
HuaMinChenSystem managerAuthor Commented:
Sorry, how to point to the relevant table within Access DB, in the above codes?
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:
The code I posted is for the click event of a command button. Havinfg the code behind the form makes it easier.

With the code behind the form you will need to change is the following line:

' open a recordset on the Attachment field
Set rsChild = rsParent.Fields("AttachmentTest").Value

Open in new window

You will need to change the AttachmentTest to be your field name


If you use a code Module:

You first open a recordset for the table with the attachment data type field

' use the form's record source
Set rsParent = Me.Recordset

Open in new window


Change the above line to open the desired recordset

Also in:
' open a recordset on the Attachment field
Set rsChild = rsParent.Fields("AttachmentTest").Value

Open in new window

You will need to change the AttachmentTest to be your field name

Either way be sure to set he output path:

rsChild.Fields("FileData").SaveToFile ("c:\")

Open in new window


Change c:\ to be the desired output folder

FWIW:
As you can see, dealing with the Attachment data type is not easy. It requires VBA coding and DAO knowledge.  I avoid them.

Boyd Trimmell, Microsoft Access MVP
0
All Courses

From novice to tech pro — start learning today.