469,290 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Using vba code to change the color of a form button in Access 2010

I have a form with a button to filter records and another to show all records. When the records are filtered I want the color of the button to change so that the user can immediately see that the records are filtered.

I changed the color on the form, noted the new color on the property sheet of the button. It is no longer a number, but text reflecting the "theme" that I am using. I tried using that text as follows:

Expand|Select|Wrap|Line Numbers
  1. cmdShowAll.Backcolor = "Accent 2, Lighter 40%"
No luck. There used to be numbers for the colors. Do I need to convert those theme colors back to numbers for the code? If so, how do I find them?
Nov 19 '11 #1
5 8452
sierra7
446 Expert 256MB
Hi Sally
There may be something new in 2010 but the old way was to set the Background Style to Transparent and then draw a coloured rectangle behind it.

You should be able to change the colour of the rectangle via VBA but I have not gotten to grips with 'Styles' yet in the 2010 and I don't know if it gets over-written.

Best of luck!
S7
Nov 19 '11 #2
Thanks for the tip. While I was working on that, I looked at the VBA property sheet for the control and it actually had the color number codes. So, I used that to set the properties with the appropriate number codes and it worked great. Thanks for taking the time to help me out!
Nov 19 '11 #3
NeoPa
32,173 Expert Mod 16PB
In truth the solution S7 was suggesting can be used, but it is only really necessary when being clever with conditional formatting. There is no reason in your situation to introduce separate elements into the mix when it can all be done with the existing control.
Nov 20 '11 #4
sierra7
446 Expert 256MB
Hi
Sally, you are correct, BackgroundColor for a button now works as expected.

Access 2003 had a background colour attribute but it didn't work, hence the trick if you really did want to change the colour, (and why I thought you had a problem in the first place).

I checked before posting and found that it still does not work in Access 2010, but I was using an 'mdb' type database. Since your post I've checked and agree that it now works as expected with a 'accdb' type database.

Thanks for pointing this out!
S7
Nov 21 '11 #5
NeoPa
32,173 Expert Mod 16PB
My mistake. I was also referring to Access 2003 but overlooked the fact (as S7 so clearly points out) that buttons do not have the facility to set a background colour. My mistake.

S7 has now clarified the situation fully though. Trust him. He knows what he's talking about (which I didn't this time :-().
Nov 21 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Dick | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.