Change picture on Command button with VBA

RECrerar

Registered User.
Local time
Today, 09:42
Joined
Aug 7, 2008
Messages
130
Hi,

I'm wondering if it's possible to change the picture (one of the built in ones) displayed on a command button by using VBA?

Basically I have comboboxes in my form that are used to select the person resposible for a certain task. There are a lot of people so I have some people defined as frequent users and a criteria on the combo box that means that initially only the frequent users are displayed. I then have a command button that when clicked once removes this criteria to show all users and when clicked again reinstates the criteria. What I would like to do is initially have the command button show the remove filter icon and then when clicked this change to the apply filter icon, but I don't know how to refer to the specific pictures in code or indeed if it is possible

Regards
Robyn
 
Last edited:
Use the .picture property of the button
 
I'm aware of the .picture property, the question is how do i refer to the specific images.

e.g cbListFilter.picture = ??????????????????????????

where cbListFilter is the name of the button
 
I can't find where Access stores the images. Perhaps someone else does.

Alternatively you can work around this by having two buttons at the same place on your form and have one with .visible=false and the other with .visible=true and just swap these when you want to change.
 
That's an interesting idea for a work around, I hadn't thought of that. I may actually give that idea a go.

Thanks, I had just given up and used text but this is much better.

If anyone does not where the images are stored it would still be useful to know.
 
ok here goes , first .picture parameter is usually filled in by a path to a bmp (or any other non jpg / transparent gif picture formats which might cause errors on enforcement) ex : mybutton.picture = "c:\myphoto.bmp" so that answers your question.

on the other hand there is a set of built in bmp photos brawseable through "picture parameter set" button in button's properties which relies on access reference library and uses index method for retrieval , however all my trials to to call a referenced picture by index and assigning it to picture property has faild in vba (on adding index number to the path returns "path not found" error) so if you realy want to use built in pictures you have to set them through "picture parameter set" button which answers the other question.
 
Hey, Thanks for the reponse

first .picture parameter is usually filled in by a path to a bmp (or any other non jpg / transparent gif picture formats which might cause errors on enforcement) ex : mybutton.picture = "c:\myphoto.bmp" so that answers your question.

Actually that doesn't really answer my question as I was aware that you could enter a path to custom image and that that path could easily be changed through VBA. My question refered to the inbuild reference library of images that you covered in the second paragraph and specifically if there was a way to refer to them through VBA.

however all my trials to to call a referenced picture by index and assigning it to picture property has faild in vba

This comment of yours is actually the closest to answering my question, and suggests that, as you have not been able to do this either and assumeing you are much more accoustomed to Access than me, that it is not possible to modify these through VBA.

I would have thought the reference library of images must be somewhere in all the Access program stuff but am happy to be wrong about that, and the method of just using two buttons in the same place is working just great, so in the unlikely event that I desire (I was going to write require but this is purely a matter of asthetics rather than performance) the same capability again I think I will use that route.

Regards
Robyn
 
Last edited:
The images are stored in binary format in Access (they used to be in the Access exe AFAICR - though some have been extracted over time).

You can store the images yourself though - as data and use accordingly.
By way of example... http://www.databasedevelopment.co.uk/examples/ImageData.ziphttp://LoadImageData.zip

It's fast and quite efficient. (Allows use of the same data in multiple controls - rather than have two controls to display each time - which adds bloat to the application).

Cheers.
 
Hi Leigh,

That is fantastic, that is exactly what I was after. Thank-you so much.

Not sure I completely understand everything that's going on yet, but I will have a closer look at the code to figure it out.

Thanks again, Robyn
 
No worries Robyn - just shout if anything's not clear.

It's slight duplication - in that we're storing an images Picture data in a table (when then image is already included in Access) but it affords us our own level of control over it and its use.

(One of the form's in the application is hidden - as it's only for loading data/images into the table).
 
just reviewd the db , ok it doesnt offer much realy in the process of image retrieval , what it does is store images in a field and retrieve it by code.

how to get the images in first place may vary.

now i say print screen can be handy , saveing captured button images in bmp and later on db can be one way.
 
>> "ok it doesnt offer much realy in the process of image retrieval , what it does is store images in a field and retrieve it by code."

I'm not quite sure what you're saying there... That it's something of a make-do solution?
I've already stated that it's only storing the image data in a table and later retrieval of that.

There have been instances (a few versions of Access back as I recall) of extraction of the built-in icon images... But even once you have them as files... where's the advantage over storing them in the table?
(Other than for use outside of Access - but there's been no mention of that as a requirement).

>> "now i say print screen can be handy , saveing captured button images in bmp and later on db can be one way."

The method I offered aquires the images in a very particular way (Access' internal image binary data format) - required for the subsequent retrieval methd of that same picture data.

Unlike an external method it maintains the icon's transparency and offers the functionality to remain entirely within Access.
There are no external files to lose. It's faster for the images to load...
I can't see how Printscreen compares at all.

To each their own eh?
 
Sorry to revive a long-dead topic, but I have the same issue and wanted to check if Leigh's suggestion is still the only valid one (I'm using Access 2010 if that helps at all)?

If not it seems overkill in my situation to add another table into my database just to change the picture on one button - so if noone else has any solutions for referencing these Access images I'll use a far easier solution (e.g. making the caption 'Toggle Filter' or alternate between Apply/Clear).


Kind regards,

Michael
 
You don't need another table per se. That's just the most flexible solution without requiring certain UI elements.
But the process of assigning the PictureData property remains.
Instead of a table, some might choose to have a form, which remains open throughout the application instance (but hidden, invisible).
On that form, add a control for each image you want to use elsewhere. And then you can use that image throughout the application such as:
Me.cmdLocal.PictureData = Forms!frmHiddenForm!imgPicture1.PictureData
and so on.
(Though, obviously, you'd really write a wrapping function to handle that.)

Access 2010 + does store images in the application in a single repository now (as opposed to separate binary data even when the same image is used elsewhere), but it's not programatically accessible that I've seen (and not played with thus far).
 
I am always underwhelmed by the bitmap images available and whilst I searched for them and didn't find any I simply made my own. I need mainly text and this is the result.

I simply use the picture property to render images and change images.

Simon
 

Attachments

  • menu.jpg
    menu.jpg
    91.2 KB · Views: 2,876
Underwhelming, to describe the buiilt-in button icons, is being a bit kind. :-p
But that doesn't prevent you from being able to assign your own images to a control, and *then* store them in a binary table as described - or even the form based method just described. Some reasons? Portability: assigning the Picture property requires an external file. Speed: It's a slower operation (can even result in a visible delay for large images), PictureData is immediately assigned.

Nothing wrong with using the Picture property other than that - but I'm just saying that finding the Access built in images as unimpressive doesn't mean you can't still use the PictureData method. It just requires some setting up first.

Cheers
 
Leigh,

I have have over 20,000 images just relating to the stock some of these are over 100KB but these are exceptional. When I started looking at images there was the choice between bitmaps and bitmaps. Even now the Command Button images are still bitmaps. The asethetic images are around 10KB.

Simon
 
That's a lot, but I'm assuming you don't use them all in any given application. ;-)
 
That is right and that is the reason I don't store images.

Simon
 
Thanks for your help guys, I'll stick with text method in that case as it is much easier.

I would've thought Microsoft would make the images more accessible but oh well.
 

Users who are viewing this thread

Back
Top Bottom