Solved

Retrieve the file

Posted on 2013-12-03
5
312 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

738 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