Full Version: using images (icons) on forms / using imagelist
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
SQLguy
I'm trying to perfect a calendar form which uses a bunch of subforms for each day.
See Screenshot here: Calendar Form

I want to use icons (like the schoolbus for school days, other icons for holidays, weekends..etc)
I tried using an image control and loading the right jpg file from a folder like this:
frm.Controls("imgStatus").Picture = CurrentDBDir() & "bus.jpg"
but that seems to be way too slow.

Then I tried using an image list, but I don't seem to be able to get it to work
I tried
frm.Controls("imgStatus").Picture = imglist01.listimages(1).Picture
and that causes the error:
Runtime error '2220'
Microsoft Access can't open the file '755309994'

Any ideas?

BTW, I'm limited to using Access 97 for now.

Edited by: SQLguy on Thu Sep 20 9:53:26 EDT 2007.
LPurvis
So you have a pre-defined list of images that you might call upon for any given insertion into an image control.
You mention a Calendar form - so it's reasonable to assume that this is a largely unbound control affair - with properties assigned in the single form instance?

Assigning images from disk to Picture controls isn't necessarily fast.
I've never tried - but I wouldn't expect the Image control solution to work - as it's an ActiveX control - and works well with other such controls (for example providing images to Treeviews) but isn't compatable with native Access controls and their properties.

So - you're looking to store the images and assign them at runtime.
Almost inevtiably in such situations I look to the PictureData property of a Picture control.
This is an Access property which holds the image information as Access renders it onscreen (as opposed to binary file data).
It allows for direct assignment of picture data from one such control to another.
So one common technique is to have open, but hidden, several image controls each with a required image on it.
Then you can use that image assigned directly to other controls which require the same picture.

Me.PictureControl.PictureData = Me.OtherControl.PictureData

However - even potentially more flexible than that, you can store the PictureData string (for that's what it is) in a Memo field (OLE not required - as it's not binary remember) and retrieve that and assign at will.
Mentioned also here.
gary84

I've got a rudimentary question.
I have a Form that will have contain about 50 Image Controls.
Only one of them will be visible at a time.
They are all sllightly different sizes.

(1) Should I create just one Image Control and changes its .Picture values to whatever I need, like "C:\Images\Picture0001.gif",
or should I create 50 Image Controls define them all individually. I never tried using just one image Control, I did not want to have to bother to the .Resize but maybe it's not the big of a deal.

(2) Also, should I keep the Image loaded in the .Picture of the Control, or should I load them in using the Sub Form_Load() event to prevent my database from exploding in size. I've been playing with it both ways and either way seems to work fine, I just don't like the way my database size doubles when the images are loaded all the time.

LPurvis
Hi

When you say having to bother with the Resize - what are you referring to?
Do you have differently sized images - and your controls are each a different size to accomodate the underlying image?

As a general rule - I'd certainly look to the one control - changing its properties as required.
Although as mentioned above and elsewhere - setting the Picture property can be less than immediate, and if the images to load are predictable then there are other ways.

If your images are linked then you need the source file in position - if embedded then your db will indeed grow in size. (I generally use bitmaps in applications for this very reason - maximum quality for a bloat in size that I'd likely get from a Jpeg anyway).

Your db growth is all dependent on how you store the images.
As I've mentioned in this question (and others related to it) - there are definite storage choices to elimiate bloat.
gary84

> When you say having to bother with the Resize - what are you referring to?

That was an error.
I was thinking of .SizeToFit

> Do you have differently sized images - and your controls are each a different size to accomodate the underlying image?

Yes.
Here's what I'm doing:
I need to be able to instantly visualize a 2-D Plan View of a physical site installation, with the Designations of the outfitting equipment (lighting fixtures, receptacles, junction boxes, telephones, and many hundreds others) automatically appearing in the foreground of the Plan View, based on the filter selected by the user.
The Plan Views that I created (about 50 of them) are Cropped images from Adobe Elements or Photoshop, set to various Scaling factors depending on the complexity and equipment density of the 2-D area being viewed. My program automatically overlays the Designations onto the Plan based on the scaling factor, the X/Y coordinate location of the equipment, does a bunch of Twips math, you know what I mean. It works great, I'm really just optimizing it, speeding it up, shrinking it as much as I can now.
Programs like AutoCad can be used for this sort of thing but I'm a control freak and it I want it to work the way I want it to work :-)

> As a general rule - I'd certainly look to the one control - changing its properties as required.

But .SizeToFit does not work unless you are in the Design View, and I do not want to close, edit, and reopen the view every time the user changes graphics so... multiple views. I only need to build the Form once, so I wrote code to do that:

CODE

Private Sub Create_Image_Controls_in_a_Form_22_Click()
    ' Open an existing Form. Create a new Control based on an Image .GIF file
    Dim MyControl As Access.Control
    Dim int1 As Long
    Dim strPicture As String
    Dim strFormToEdit As String
    
    strFormToEdit = "Form1"
    DoCmd.OpenForm strFormToEdit, acDesign
    
    Do
        int1 = int1 + 1
        Set MyControl = CreateControl(strFormToEdit, acImage)
        MyControl.Name = "Image" & int1
        MyControl.Top = 5000 + 100 * (int1 - 1)
        MyControl.Left = 1000 + 100 * (int1 - 1)
        strPicture = Right("000" & int1, 3)
        MyControl.Properties("Picture") = "c:\Image Libary\" & strPicture & ".gif"
        MyControl.SizeToFit
    Loop Until int1 = 50
End Sub



> If your images are linked then you need the source file in position

Yep I got that covered, see above.

> if embedded then your db will indeed grow in size.

Man, will it ever! Sheesh! It was just going gaga. After I cleared the contents and every "Picture" property and switched to the method shown below my database shrunk in size dramatically, less than a third the size. Much faster Compact & Repair duration too.

> As I've mentioned in this question (and others related to it) - there are definite storage choices to eliminate
bloat.

Exactly. This is what I finally decided to use. Note that the Control named Box01 is used as a target.

CODE

Sub TurnOnImages()
    Dim db As DAO.Database
    Dim rst1 As DAO.Recordset
    Dim strControlname As String
    
    Set db = CurrentDb
    Set rst1 = db.OpenRecordset("T01_Pictures", dbOpenDynaset)
    
    Do
        strControlname = rst1![ControlName]
        Me.Controls(strControlname).Visible = False
        Me.Controls(strControlname).Picture = rst1![Filename] ' strFilename
        Me.Controls(strControlname).Left = Me.Controls("Box01").Left
        Me.Controls(strControlname).Top = Me.Controls("Box01").Top
        
        rst1.MoveNext
    Loop Until rst1.EOF
    
    rst1.Close
    db.Close
End Sub


Huge improvement. Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.