Need to use VBA to put image on a form

  • Thread starter Thread starter Earl Kiosterud
  • Start date Start date
E

Earl Kiosterud

Hello folks,

I need to have an event-fired sub put an image on a form. It needs to be fired when the
form is advanced to the next record. I don't know how to code it. Thanks
 
I think that was a bit too terse. The image I want to put on the form is a jpg image, the
file name of which I'll be able to get from a field in the record in the associated table.
There's an image for each record.

--
Earl Kiosterud
www.smokeylake.com

Note: Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Hi Earl,

Use an Image control to display the photo, and place code like the following
in the Current event of the form. This assumes that the path/filename of
the image file
is in a textbox control named txtImageFile, bound to the table field where
the path/filename is stored. I use the same code in the AfterUpdate event
of the textbox to update the picture if the path/filename is changed.

If Not IsNull(Me.txtImageFile) Then
Me.imgImage.Picture = Me.txtImageFile
Else
Me.imgImage.Picture = ""
End If

If you don't want to have the image filename visible on your form, you can
hide the textbox control, or simply refer to the field in the code, rather
than to the control holding the field's content; in that case, the first
line would be:
If Not IsNull(Me!ImageFieldName) Then

And another tip - if you set the Size Mode of the image control (it's on
the Format tab in the Properties dialog) to Zoom, your image will resize to
fit the control, and retain its aspect ratio.

Finally, to prevent possible crashes when scrolling through records, you
should incorporate the registry changes described here:
http://www.mvps.org/access/api/api0038.htm

HTH,

Rob
 
Rob,

Worked great. Thanks. I got questions -- you got answers! Only this ain't Radio Shack.

I changed the Picture Type property to Linked (don't need to keep it in the data base). I
added code to check for the existence of the image file and reset the image
(Me.Image15.Picture = "") if it doesn't exist.

Is there a control that will let me increase the size of the image, then use scroll bars to
pan around? I've looked at all the properties of the Image control that I'm using now, and
I don't see anything.

--
Earl Kiosterud
www.smokeylake.com

Note: Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
 
Hi Earl,

Glad it's working. As for your latest question: the standard image control
(or the bound or unbound OLE controls) does not let you resize, or provide
scrollbars. You set it to the size you want your image to display at
on-screen, and that's it. As I said in my earlier post, if you set the size
mode to zoom, your image will always be displayed fully (ie, not clipped,
and possibly expanded to fit but still retaining its original aspect ratio).

There may be a third-party control which will do what you want, but I'm not
aware of any.

Rob
 
HI Rob,
the OP can place an Image control, sized to 22. in x 22 in. on a form sized
the same. In this way the form's native ScrollBars can be used to scroll the
contents of the Image control. For a sample MDB using this method see:
http://www.lebans.com/loadjpeggif.htm

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen,

Thanks. I put the image in a separate form (so the buttons and text boxes on the first form
will be unaffected by the scrolling), and made it large as you suggested. That does give me
scroll bars, but only because I've made the image large, but still unzoomable. The user
needs a normal image sometimes and a zoomed image sometimes. I've looked briefly at your
A2KLoadJpegGifVer30D.mdb. Nice. I can probably integrate it into this attempt in Access
and get the zoom capability. But there's more needed.

Let me take a moment to describe the project. It is replacing a data entry form that's
currently implemented in Excel (which I can make dance and sing with VBA, though I can't yet
with Access). As the user goes through each record a document image is fetched and placed
onscreen. The user sometimes needs to visually extract information from the image, which is
then keyed in. Some images are difficult to read. The Excel program allows for zooming,
changing contrast and brightness, and rotating 90° left. These are the image capabilities
we need.

Is there functionality available for any of rotating and changing brightness and contrast?
 
While your Image manipulation requriements could be accomplished directly in
VBA under Access it would be a complex process for a developer without a lot
of GDI experience.
An alternative would be to embedd the image as an OLE object. For example
you could embedd a blank Excel SpreadSheet. At runtime, insert the desired
Image into the Excel sheet via Automation. YOu could then use the Excel
Picture TollBar as you are currently.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Stephen,

Thanks. The embedded OLE object with Excel automation sounds workable. I'll get to work on
it.
--
Earl Kiosterud
www.smokeylake.com

Note: Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
 
Back
Top