Solved

Retrieve the file

Posted on 2013-12-03
5
311 Views
Last Modified: 2013-12-18
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?
0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39694556
If you have path to image in table, you can use method from my article:
Images on continuous forms
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39694561
Sorry, there are already images stored in the table but I want to retrieve the file from the table.
0
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 135 total points
ID: 39694726
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39694735
Sorry, how to point to the relevant table within Access DB, in the above codes?
0
 
LVL 21

Assisted Solution

by:Boyd (HiTechCoach) Trimmell, Microsoft Access MVP
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 135 total points
ID: 39696282
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

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question