Attachment image as image picture

B

Brian

I am trying to set an image dynamically at runtime. I have several images
stored in a table using a single attacment per record.
I can already determine the correct image and retreive it's data using :
rsForm.Fields("Images").Value
however when i try to set the image to this:
imgTestPic.PictureData = rsForm.Fields("Images").Value
i get the following error: 2192: The bitmap you specified is not in a
device-independent bitmap (.dib) format.
I can however set the image to an external file:
imgTestPic.Picture = "C:\testicon.ico" so the setting works.
So how do i convert my stored Imagge bitmap to a DIB???
Geatly appreciate any assistance...
 
J

Jack Leach

AFIAK, to display an image in a standard picture control, it does not need to
be a DIB format file.

You first reference the .PictureData property, then the .Picture property...
did you perhaps have a typo? Have you tried setting the .Picture property
with the field value rather than the PictureData property?

As a side note, I generally always store the image in a folder (either the
BE folder or FE app folder depending on the nature of the image) and set the
Picture property of the image control to the path of the file.

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
B

Brian H

Hi Jack Thanks for trying, but...

setting TestPic.PictureData = rsForm!icon.Value
seems to load somthing but does not display an image!

setting TestPic.Picture = rsForm!icon.Value
results in a Type mismatch

Pretty sure there are no typo's
 
J

Jack Leach

Have you checked the help file on the .PictureData property? I don't believe
this is what you want... it is used for transferring properties from one
object to another and doesn't seem to have a place in your situation.

The .Picture property takes a String datatype... ex.
"C:\SomeFolder\SomeFile.bmp" If you are getting a type-mismatch then you are
not supplying it with a string value. What is the value of
rsForm!icon.Value? For the record, icon may be a reserved word (not sure on
this, but I'd avoid using any word that has meaning aside from your control.
Maybe you should prefix it with "img" or "ctl" or something).

Also, you should make sure the PictureType property is set to Linked rather
than Embedded.


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
B

Brian H

Hi Jack,
Yes the .Picture prop takes a string usually a file path/name.
I am using an attacment field in a form as the image source.

the code is:
Static frmImages As Form
Static rsForm As DAO.Recordset2
DoCmd.OpenForm "Icons" 'WindowMode:=acHidden
Set frmImages = Forms("Icons")
Set rsForm = frmImages.Recordset
rsForm.FindFirst "Description='" & "Face'"
If rsForm.NoMatch Then
' No image found
Else
Me.TestPic.Picture = rsForm!imgSource.Value '=Type Mismatch
Me.TestPic2.PictureData = rsForm.Fields("imgSource").Value '=
Nothing happens but Me.TestPic2.PictureData remains Null.
Me.Repaint
Me.Requery
End If

So how do i get an image from the attachment to an image control other than
Picturedata???
 
D

Dirk Goldgar

Brian H said:
Hi Jack,
Yes the .Picture prop takes a string usually a file path/name.
I am using an attacment field in a form as the image source.

the code is:
Static frmImages As Form
Static rsForm As DAO.Recordset2
DoCmd.OpenForm "Icons" 'WindowMode:=acHidden
Set frmImages = Forms("Icons")
Set rsForm = frmImages.Recordset
rsForm.FindFirst "Description='" & "Face'"
If rsForm.NoMatch Then
' No image found
Else
Me.TestPic.Picture = rsForm!imgSource.Value '=Type Mismatch
Me.TestPic2.PictureData = rsForm.Fields("imgSource").Value '=
Nothing happens but Me.TestPic2.PictureData remains Null.
Me.Repaint
Me.Requery
End If

So how do i get an image from the attachment to an image control other
than
Picturedata???


I suggest you poke around a bit on www.lebans.com . Stephen Lebans has done
some pretty complicated work with image processing in Access. Also, Larry
Linson has an example where he writes the BLOB to a temporary file, then
sets an Image control's Picture property to that file's path. That's in his
Imaging Examples database, which can be downloaded from
http://accdevel.tripod.com/imaging.htm .
 
B

Brian H

Hi Dirk, Yes Steven Lebans stuff is amazing! I was hoping for a slightly
simpler solution than a full API Class conversion. I must admit I am
surprised how hard MS have made it to use the Attachment objects.
I think i will go with the external File folder rather than spend a week
coding the GDI API. But this would be a good challenge if I ever find some
spare time!!!
Thanks to both you and jack for trying...
Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top