I have a label in an Access 2007 form and I am trying to change the background color based on the value of a checkbox. My code is below and, although I don't receive any errors, it doesn't work. What am I doing wrong?
Check the BackStyle property of the label. If it's set to Transparent (the default), the BackColor property will be ignored. To see the BackColor, set BackStyle to Normal.
If you want to do this in VBA:
I changed the attribute to normal and still did not work. Then, I changed my color to &HCF7B79 and that made no difference. Oh, I changed the backstyle in the properties sheet, not in VBA - would that matter?
Changing the property in the Property Sheet should be sufficient.
Could you create a copy of the database with just the items needed to demonstrate the problem? Remove everything not relevant to the problem, and all sensitive/proprietary information, then zip the copy and attach it to a reply.
Thanks in advance.
You can search for a word such as NoGoColor by selecting Edit | Find... in the Visual Basic Editor. You can specify that you want to search the entire project (i.e. all code in the database):
S0073.png
You do not have the required permissions to view the files attached to this post.
If you read "The importance of 'Option Explicit'" carefully, you'll see that you shouldn't insert this line inside a procedure (sub) but at the top of the module, above all procedures and functions.
Hmmm, I though I had it. Now I am not sure where to put it. Seems like I recall a lot of code from you that had Option explicit but cannot seem to find any of it now. I was sure you had it in there somewhere. I already have one option at the top... is that where it goes? pardon the spelling in the image.
You do not have the required permissions to view the files attached to this post.
You can insert the line Option Explicit immediately above or immediately below the line Option Compare Database. As long as it is above the first Sub or Function in the module.
Okay it works now... sort of. I set it up as an onclick event and it seems to work as designed but not what I need.
If the NoGo check box is already checked, then the back ground color does not appear unless I click it off then click it back on (uncheck then re check). I think I have the wrong trigger event.
If the box is already checked then the background should already be in a different color when I come to the record and if it is not already checked then the background should be white until it is checked.
You also need to create an event procedure for the On Current event of the form. This will set the background color when the form is opened, and when you move from record to record: