PDA

View Full Version : Images in MS Access 2010



mickyoung
05-15-2012, 01:52 PM
I have a field in my database that contains a Jpeg. I have written a VBA module to transfer field data from the database to a MS Word document , the text transfers fine, but when I try to transfer the field with the image it generates an error.
Is it possible to transfer an image between Access and Word?

HiTechCoach
05-16-2012, 09:08 AM
It would help to know what your VBA does.

Are you using automation to perform a mail merge with Word 2010?

mickyoung
05-16-2012, 02:21 PM
HiTechCoach

The code basically creates a new word document, draws a table and populates the cells with the database data .

Example of code is
' Get the data from the database
Set db = CurrentDb()
Set rs = db.OpenRecordset("ITEM")
Set fldloc = rs.Fields("LOCATION")
Set fldequip = rs.Fields("DESCRIPTION")
Set fldpriatt = rs.Fields("PRIMARY")
Set fldsecatt = rs.Fields("SECONDARY")
Set fldinspect = rs.Fields("EQUIPMENT")
Set fldcontrol = rs.Fields("CONTROL")

' Pass the data from database recordset to table
Do Until rs.EOF
Set oRow = oTable.Rows.Add
myRow.Cells(4).Range.Font.ColorIndex = wdRed
myRow.Cells(1).Range.Text = fldloc
myRow.Cells(2).Range.Text = fldequip
myRow.Cells(3).Range.Text = fldpriatt & vbCrLf & fldsecatt
myRow.Cells(4).Range.Text = fldinspect
myRow.Cells(5).Range.Text = "Signature"

rs.MoveNext
Loop

The other field that exists in the database that I would like to transfer is a photo. Ideally what I am trying to achieve is to see a thumbnail size photo in the document and have a hyperlink to the parent photo file on the disk.

I am a newbie to VBA and am using this as a project to teach myself.

Hope this explains a little better.

HiTechCoach
05-21-2012, 09:41 AM
Where are you storing the photo?

mickyoung
05-21-2012, 12:19 PM
HiTechCoach,

I am planning to use a fixed folder structure, in that:

Main Folder
-Database
-Photographs
-Word Reports
This way any user will follow the same process and save all photos to the relevant folder.
Then when they create a new record in the report they access the folder from the attachments field.
In the mean time I have created another textbox in the form where the user has to insert the photo file name and because the file folder structure will be fixed I have just used this line to add the picture.

oRow.Cells(1).Range.InlineShapes.AddPicture photoloc, linktofile:=False,_ savewithdocument:=True

where photoloc is a string pointing to the folder with file name from field added on the end.

A little scruffy but it has allowed me to progress.

In an ideal world I was trying to use the information already stored in the attachment.
When I create a query and look at the attachment field I see something similar to this:-
- Field1
Field1.FileData
Field1.FileName
Field1.FileType
I was trying to tap into this info to get the file name for the picturebox and for the hyperlink, but it doesn't appear possible(beginner talking).

Thanks for the interest in my problem.

Mick