TrilobyteMKR
asked on
Reset the theme for a command button in Access 2010 VBA
I want to set a command button to have a different font color when selected. When this button loses focus i want the button to revert to its orinial theme colorscheme.
e.g.Private Sub Command1_Click()
Me.Command1.ForeColor = vbRed
Me.Command1.BackColor = vbYellow
then the button loses forcus I want to reset the colors back to the original scheme using VBA.
e.g. Backcolor Accent 1, Lighter 40%. Forecolor Text1 Lighter 25%
Thanks
Malcolm
e.g.Private Sub Command1_Click()
Me.Command1.ForeColor = vbRed
Me.Command1.BackColor = vbYellow
then the button loses forcus I want to reset the colors back to the original scheme using VBA.
e.g. Backcolor Accent 1, Lighter 40%. Forecolor Text1 Lighter 25%
Thanks
Malcolm
ASKER
I've tried that using a spare button but it doesn't restore the colors in the same way as the original buttons, M
The system colours are coded as negative numbers. For example, I just created a new form and set the detail section background to “Background Light Header”. Then, from Visual Basic's Immediate Pane, I typed:
? Forms(0).Detail.Backcolor
-2147483612
? Hex(Forms(0).Detail.Backco lor)
80000024
I find the second version more readable. Anyway, you can reset your control to the same colour using one of:
(°v°)
? Forms(0).Detail.Backcolor
-2147483612
? Hex(Forms(0).Detail.Backco
80000024
Me.Command1.BackColor = -2147483612
Me.Command1.BackColor = &H80000024
I don't know why als315's suggestion to store the value didn't work. Perhaps like this? (With a little more context...)Option Explicit
Dim mlngSavedColor As Long
Private Sub Command1_Enter()
mlngSavedColor = Command1.ForeColor
Command1.ForeColor = vbRed
End Sub
Private Sub Command1_Exit(Cancel As Integer)
Command1.ForeColor = mlngSavedColor
End Sub
Cheers!(°v°)
ASKER
This is the code I use
Private Sub Command1_Click()
Me.Command1.ForeColor = vbRed
Me.Command1.BackColor = vbYellow
ClearButtons
Me.Command5.Visible = True
Me.Command6.Visible = True
Me.Command7.Visible = True
Me.Command8.Visible = True
End Sub
and when its lost focus
Private Sub Command1_LostFocus()
Me.Command1.UseTheme = True
Me.Command1.BackColor = Me.Command22.BackColor
Me.Command1.ForeColor = Me.Command22.ForeColor
End Sub
command 22 is a new button that is never used it is just there to retain the original color and theme details.
Trust me the color of the button when 'lost focus has been trgiggered ' is different.
It is a flat color of a deeper shade than the original buttons ; try it.
M
Private Sub Command1_Click()
Me.Command1.ForeColor = vbRed
Me.Command1.BackColor = vbYellow
ClearButtons
Me.Command5.Visible = True
Me.Command6.Visible = True
Me.Command7.Visible = True
Me.Command8.Visible = True
End Sub
and when its lost focus
Private Sub Command1_LostFocus()
Me.Command1.UseTheme = True
Me.Command1.BackColor = Me.Command22.BackColor
Me.Command1.ForeColor = Me.Command22.ForeColor
End Sub
command 22 is a new button that is never used it is just there to retain the original color and theme details.
Trust me the color of the button when 'lost focus has been trgiggered ' is different.
It is a flat color of a deeper shade than the original buttons ; try it.
M
Harfang's example is working. May be you have any problems with Command22 button? Try to use variable, as we recommended
ASKER
Either I'm missing the point or I'm not making myself clear.
If I try the immediate window I get
?forms!frm_viewer!command1 .backcolor
14136213 (not a negative number)
If I apply this to the button as a background color it is a flat color, it is not graduated like the original button is (Accent 1, Lighter 40%).
The background on the original button is lighter at the top and darker at the bottom as if it has been graduated in Photoshop.
buttoncolor.jpg
If I try the immediate window I get
?forms!frm_viewer!command1
14136213 (not a negative number)
If I apply this to the button as a background color it is a flat color, it is not graduated like the original button is (Accent 1, Lighter 40%).
The background on the original button is lighter at the top and darker at the bottom as if it has been graduated in Photoshop.
buttoncolor.jpg
It is clear now - if you are changing Back Color, gradient (which is somewhere in quickcolor parameters) go out.
It is new parameter, introduced in Access 2010 and seems there is a bug.
If you will change only ForeColor, style remains same.
May be it could be temporary solution for you. I will ask other experts, may be anybody have othe solution.
Included is example for testing. It can be tested only in Access 2010
ButtonColors.accdb
It is new parameter, introduced in Access 2010 and seems there is a bug.
If you will change only ForeColor, style remains same.
May be it could be temporary solution for you. I will ask other experts, may be anybody have othe solution.
Included is example for testing. It can be tested only in Access 2010
ButtonColors.accdb
Sorry, in that case my comment doesn't apply. I don't have Access 2010 yet, and can't explore the new properties; follow als315's lead, the gradient property seems promising.
(°v°)
(°v°)
I have bad news: SP1 for Office 2010 have not fixed this issue and seems there is no answer to your question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or there is some undocumented feature
ASKER
It is a bug so there is no solution
> It is a bug so there is no solution
Microsoft doesn't consider this a bug... Please read Use Windows themes in controls on forms, and in particular the section “Control customization reference”:
When you enable Windows-themed controls in a database, the Access controls will use the Windows theme that is applied until you change certain display properties for those controls.
The list of these properties doesn't contain the ForeColor and BackColor property, but it does contain the BorderStyle. Since you also change that property (if I read your illustration correctly), you effectively disable windows themed controls, as per this documentation.
Please try again, using only the property in your question: ForeColor.
See also: CommandButton Members (Access)
(°v°)
Microsoft doesn't consider this a bug... Please read Use Windows themes in controls on forms, and in particular the section “Control customization reference”:
When you enable Windows-themed controls in a database, the Access controls will use the Windows theme that is applied until you change certain display properties for those controls.
Please try again, using only the property in your question: ForeColor.
See also: CommandButton Members (Access)
(°v°)
Dim Fc, Bc as variant (not in sub, after Option Compare Database in form's module)
in click sub:
Fc = Me.Command1.ForeColor
Me.Command1.ForeColor = vbRed
in lostfocus event:
Me.Command1.ForeColor = Fc
and same for backcolor