Change background color of button (1 Viewer)

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
I am trying from a button in the main form to change the background color of another button in a continuous subform header section

Forms![frmConcilManual]![frmSBancoNCont_P].Form![Command58].BackColor = RGB(255, 242, 0)
[frmSBancoNCont_P].Form.Repaint

frmSBancoNCont_P is the name of the control and form name aswell

i can change the color if the target button is in main form , but not if it is in the subform.
Any ideas ? thanks
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:02
Joined
Feb 28, 2001
Messages
27,186
It is possible that you are getting caught on a subtlety of forms. If, as you describe, the button in question is in the header of a form for which the details are in continuous mode, you need to tell Access that the control you wanted is in the header section.


You might need to reference something like this:

Code:
Forms![frmConcilManual]![frmSBancoNCont_P].Form.Section(acHeader)![Command58].BackColor = RGB(255, 242, 0)

Or, since sometimes the symbolic section names aren't defined, and since acHeader = 1, just use ...Form..Section(1)!...
 

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
Thanks for your reply. I get an error : Run-Time error '438' Object doesn't support this property or method
I am going to create a new form from scratch, and test it.
Shouldnt I set the focus to the subform before i change the back color of the button ?
 

June7

AWF VIP
Local time
Today, 05:02
Joined
Mar 9, 2014
Messages
5,472
Subform does not require focus. Must use subform container control name. Since container has same name as subform, your code should work. Does for me. I always name container different from the object it holds, like ctrBanc. The Repaint is not necessary.

And no, don't need to reference section.

Since code is behind main form, could use Me.

Me.ctrBanc.Form.Command58.Backcolor = RGB(255, 242, 0)
 

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
I did as June7 suggested, changed the name of the control to ctrSBancoNCont_P, so that it is different from the actual form name

Me.ctrSBancoNCont_P.Form.Command58.BackColor = RGB(255, 242, 0)

no errors, but still, no color was changed.
the path to the button is now correct since Me.ctrSBancoNCont_P.Form.Command58.caption="XX", results in changing the caption.
I wonder why the background color wont change
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:02
Joined
Sep 21, 2011
Messages
14,306
Do yourself a huge favour.
Give your controls meaningful names.
Command58 is not going to mean anything to you a few days down the road. Nor to any poor sod who has to take it over from you. :(
 

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
CJ_London,
Enabling the button does not work
Me.ctrSBancoNCont_P.Form.Command54.Enabled = True '
Me.ctrSBancoNCont_P.Form.Command54.BackColor = RGB(255, 242, 0)

Would you mind take a look, maybe it works with you. I attached a copy.
Thanks
 

Attachments

  • button color.accdb
    812 KB · Views: 82

Gasman

Enthusiastic Amateur
Local time
Today, 14:02
Joined
Sep 21, 2011
Messages
14,306
What version of Access are you using?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:02
Joined
Sep 21, 2011
Messages
14,306
 

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
yes there is a property to change the back color
 

Attachments

  • prop.jpg
    prop.jpg
    59.5 KB · Views: 74

cpampas

Registered User.
Local time
Today, 06:02
Joined
Jul 23, 2012
Messages
218
Gasman,
That worked great. Many thanks for your kind help
Cheers
 

June7

AWF VIP
Local time
Today, 05:02
Joined
Mar 9, 2014
Messages
5,472
Using Access 2010. I have never done anything with themes. I have no idea how to enable or disable themes. The "Quick Styles" icon is greyed out.
Code to set button backcolor works for me.
 

Users who are viewing this thread

Top Bottom