Solved

Retrieve the file

Posted on 2013-12-03
5
306 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
  • 2
  • 2
5 Comments
 
LVL 39

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now