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.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Upvote 0
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.
 
Upvote 0
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]"
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top