change color of the command buttons (1 Viewer)

JHB

Have been here a while
Local time
Today, 11:50
Joined
Jun 17, 2012
Messages
7,732
...The only problem occurs when I close the form and I reopen the form, the backcolor of the command buttons reverts back to their original color.
Because you change it back in the form's OnOpen event.
Code:
Private Sub Form_Open(Cancel As Integer)
SetCtlProps Me
End Sub
..
..
Sub SetCtlProps(frm As Form)
    Dim ctl     As Control
        
    For Each ctl In frm.Controls
        Select Case ctl.ControlType
            Case acCommandButton, acToggleButton
                ctl.ForeColor = 0
                ctl.BackColor = 16777215
                ctl.UseTheme = False
            Case acTabCtl
                ctl.BackColor = 15777815
        End Select
    Next ctl
End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:50
Joined
May 21, 2018
Messages
8,527
There is something else going on. There is something with the format on those buttons, and I cannot figure it out. See my demo using new buttons. On any form, in the on open event if you add
ChangeButtonColor Me

It will change the button colors to the colors I save in the table. See modSettings and my table tblSettings.

But there is something about the format of those buttons that you are using. You are correct, you can change the background in design view but it will not show. By chance are they copied from an older database? I left one in my demo.
 

Attachments

  • MajP_PersistColor.accdb
    1.4 MB · Views: 121
Last edited:

wire_jp

Registered User.
Local time
Today, 02:50
Joined
Jun 23, 2014
Messages
64
Hi Everyone,

Thank you for the help. I will spend some time to implement these changes and if I have any more issues, I will post back later.

Thanks again.
 

isladogs

MVP / VIP
Local time
Today, 10:50
Joined
Jan 14, 2017
Messages
18,211
Hi MajP
Thanks for your example which in some ways nicely complements my sample database which sets the state of groups of controls using the tag property.
https://www.access-programmers.co.uk/forums/showthread.php?t=293439

I may well adapt this for my own purposes.

For info, there are a couple of issues with the example which are easy enough to fix.
1. The Exit button code doesn't work
2. Clicking English displays a combo but it isn't clear what it's purpose is here.
Presumably to change the language as well but the referenced table is missing

As mentioned earlier in this thread, there is a similar example somewhere in this forum but I couldn't locate it easily.
Suggest you add this to sample databases.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:50
Joined
May 21, 2018
Messages
8,527
@ridders,
The OPs sample was 74 megs. I just took his switchboard for demonstration to try to figure out the deal with the original buttons. I had to remove all his tables and other code. He had code associated with those buttons. No intent was to make this a generic example. However, I kept these other buttons to try to understand why these older style buttons cannot be edited. Take a look at "This is and Old Button" and try to edit it. The code will not set the background, and you cannot edit the background in design view and have it display that background. The English button did work in the OP's case, but that is also an example of one of the non-editable for its background. Any idea on this? Try in design view to edit the background. It will show in design view, but not in form view.
Code:
For info, there are a couple of issues with the example which are easy enough to fix.
1. The Exit button code doesn't work
2. Clicking English displays a combo but it isn't clear what it's purpose is here. 
Presumably to change the language as well but the referenced table is missing
 

isladogs

MVP / VIP
Local time
Today, 10:50
Joined
Jan 14, 2017
Messages
18,211
Ah. I hadn't realised it was based on the OP's own database and can't see where @wire_jp has attached anything.

Anyway, I can still adapt the idea at some point for my own use.

As for the old button, if you have a form created with themes switched off and add some buttons, then turn on themes, the existing buttons won't update automatically.

However its easy enough to fix.
In the button properties, change Use Theme to Yes then modify as necessary to match the other buttons. In this case switching on themes makes the button a 3D raised button.

Quicker still, click a 'new' button then click Format Painter & click the 'old' button(s). The theme & formatting will be applied in its entirety
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:50
Joined
May 21, 2018
Messages
8,527
Quicker still, click a 'new' button then click Format Painter & click the 'old' button(s). The theme & formatting will be applied in its entirety
On the original I modified the theme property and still had no luck. But I never thought of just using the format painter. Learn something new every day.

can't see where @wire_jp has attached anything.
Looks like they deleted the post. It was a pretty extensive db, and may not want it to get out.
 

isladogs

MVP / VIP
Local time
Today, 10:50
Joined
Jan 14, 2017
Messages
18,211
On the original I modified the theme property and still had no luck. But I never thought of just using the format painter. Learn something new every day.

Both methods work for me.
I use the Format Painter regularly partly to update buttons on old forms I created pre-2007
Its so useful I've added it to the QAT
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:50
Joined
May 21, 2018
Messages
8,527
@ wire_jp
I will spend some time to implement these changes and if I have any more issues, I will post back later

FYI. The db you posted was 74 megs. I deleted all the objects out and compacted and repaired and it was still 68 megs. I created a brand new db and imported all your objects and the new db was 8 megs. Before this gets corrupted I strongly recommend you do the same.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:50
Joined
May 21, 2018
Messages
8,527
@Ridders
Hi MajP
Thanks for your example which in some ways nicely complements my sample database which sets the state of groups of controls using the tag property

So I added a third form on your demo to basically do the same thing with Tags and the persisted settings. I added quite a few more settings, but you could add as many as you want. Not so sure about the utility of this, but maybe for people who are color blind or have other visibility issues they can pick colors and fonts to see on forms. It is a good demo of the color and font picker, writing to a table, and pulling settings from a table.

@Wire_Jp
The code in the demo is cleaner if you want to incorporate it.
 

Attachments

  • SetControls - Color.accdb
    1.1 MB · Views: 122

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:50
Joined
Sep 12, 2006
Messages
15,650
An alternative would be to use a clickable label rather than a button.
Easier to manage background colours with labels.
 

wire_jp

Registered User.
Local time
Today, 02:50
Joined
Jun 23, 2014
Messages
64
Hi All,

@MajP: thank you for the advice and the updates to the database application. I will apply them to my database.

@ gemma-the-husky: thank you for the advice.
 

Users who are viewing this thread

Top Bottom