Changing an Embedded image on a button with code

JONeill

Board Regular
Joined
Sep 2, 2018
Messages
58
I have a sort button I want to change the picture on between the embedded images of "Sort Ascending" and "Sort Decsending". Since they're embedded within Access, I'm not sure what I need to do to get to it. I do remember seeing something about resource databases that are kind of like system dbs. Of course the other issue is that I'm developing on 2013 and it will be run in 2007. Not sure if there would be any issues with that.
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,900
make both images invisible, then depending on the button clicked, make that 1 image visible
Rich (BB code):
sub btnSortA_click()
   imgA.visible = true
imgD.visible = false
end sub
sub btnSortD_click() imgA.visible = false imgD.visible = true end sub
 

JONeill

Board Regular
Joined
Sep 2, 2018
Messages
58
The problem is that I don't know how access the location of the image. It's not in a folder somewhere. What I did was to use the picture type in the button's properties sheet and then press the ellipse button. Then, I scrolled through the "Available Pictures" in the "Picture Builder" dialogue. The initial picture is named "Sort Descending". I need to find a way to load the "Sort Descending" when the user clicks the button. I suppose I could create two buttons and make them visible=true/false but that's not really a very clean solution. So, I need to find some way through code to get to that other button.
 

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
There is a way to do this, it isn't straightforward to explain but its easy enough to implement when you know what you are doing.

Firstly create a new command button on a form (any form should do), set the picture to be the picture you want to be able to use. change the picture type property of the command button from embedded to Shared.

Now if you access the MSysResources table you will see an entry has been created for that picture. It will have been given the name of your command button so rename it something more user friendly (Say - 'SortDesc'). (this is a hidden system table, you need to select to view it in properties, alternatively the following query should work)

Code:
SELECT * FROM MSysResources


You need to repeat this for every image you want to use.
now on the event where you want the picture to change you should be able to access that picture:

Code:
Me.[I]YourCommandButton[/I].Picture = "[COLOR=#008080]SortDesc[/COLOR]"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,987
Messages
5,526,068
Members
409,685
Latest member
Davetom

This Week's Hot Topics

Top