473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

How to change label color of checkbox when checked?

37
I am trying to change the label color of a checkbox on a subform if it is checked.

The code I have so far is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Emergency_Contact_Click()
  2. If Me.Emergency Contact = True Then
  3. Me.Label23.BackColor = vbYellow
  4. Me.Label23.BackStyle = 1
  5. Else
  6. Me.Label23.ForeColor = RGB(0, 0, 0)
  7. Me.Label23.BackStyle = 1
  8. End If
  9. End Sub
The problem is that when the checkbox is checked, the label is highlighted for all records. I only want the label to be highlighted for the individual record in which the checkbox is checked.

Is there a work-around for this problem?

Thanks,
Yappy
Mar 2 '11 #1

✓ answered by NeoPa

You seem to be misunderstanding the different types of values :
"-1" <> -1
"Yes" <> Yes

The two values on the left are string values, whereas those on the right are numeric (Yes is a Boolean, but also numeric). If you must turn the TextBox value into a string (It would probably suit your purpose better to keep it as the value of [Emergency Contact] and simply use the .Format property to display Yes or No as required.), I would use the following for your IIf() statement as comparing a Boolean value to True or False is superfluous (as it already is either True or False) :
Expand|Select|Wrap|Line Numbers
  1. =IIf([Emergency Contact], 'Yes', 'No')

5 13784
NeoPa
32,556 Expert Mod 16PB
You could look at Conditional Formatting, but otherwise it can't work. See Why Values in Unbound Form Controls do not Persist if you need an explanation why.

Conditional Formatting only works with controls that contain data of course though, so you will need to be a little creative.
Mar 2 '11 #2
yappy77
37
Conditional Formatting is greyed out when I click on the label or the check box in design view. Does this mean I am unable to use conditional formatting?
Mar 2 '11 #3
NeoPa
32,556 Expert Mod 16PB
Certainly not for those controls (The label contains no data and the CheckBox has nothing to format).

If you were to create a TextBox though, that reflected the value in the CheckBox, this could be used to highlight checked records. This was where I was leading when I posted "so you will need to be a little creative".
Mar 2 '11 #4
yappy77
37
Ok. So I created the text box as you suggested and set the conditional formatting. The formatting is not working. Here is the code that I have in the text box:

Expand|Select|Wrap|Line Numbers
  1. =IIf([Emergency Contact]="-1","Yes","NO")
The conditional formatting is as follows:
Field Value is equal to Yes then fill is Yellow

Please help. Thanks!
Mar 7 '11 #5
NeoPa
32,556 Expert Mod 16PB
You seem to be misunderstanding the different types of values :
"-1" <> -1
"Yes" <> Yes

The two values on the left are string values, whereas those on the right are numeric (Yes is a Boolean, but also numeric). If you must turn the TextBox value into a string (It would probably suit your purpose better to keep it as the value of [Emergency Contact] and simply use the .Format property to display Yes or No as required.), I would use the following for your IIf() statement as comparing a Boolean value to True or False is superfluous (as it already is either True or False) :
Expand|Select|Wrap|Line Numbers
  1. =IIf([Emergency Contact], 'Yes', 'No')
Mar 7 '11 #6

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

Similar topics

10
by: Steve | last post by:
I'm not sure if I should be using tables here to structure the layout or if CSS is okay. I have a data entry form in which I have floated the labels to one side, and given them a specific width....
7
by: Don | last post by:
Via JavaScript within the client page containing the checkbox, I'm trying to capture the value of a checkbox to make a cookie out of it. But, all I get is the defined "ON" value, even when it is...
2
by: bebop | last post by:
I'm using three checkbox web controls in C# .NET and one button, and one labe Is there a way to "group" these individual checkbox web controls If so, do I use a for loop, hashtable, array,...
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
1
by: VB Programmer | last post by:
Simple: I have a datalist that is holding a bunch of job opportunities. Beside each opp (in the item template) there's a checkbox that says "apply". After the datalist there's a button that...
16
by: GTi | last post by:
I want to use a 'smarter' checkbox using span. When a user press the text the checkbox is checked. But this dos't work as expected. Any idea? <span style="cursor:pointer;"...
1
by: Chris | last post by:
Hello, Is it possible change the default color of a link label and basically override the client side settings? I need another color on my site for the links other than Blue (unvisited) and...
3
by: cvijaykrishna | last post by:
i have a web based website in which i have some 14 tabs(i took labels) i placed all 14 tabs controls in 14 different views of a multiview and in the click event of each label i am writing ...
2
by: honey99 | last post by:
Hi! i have a problem in firefox.I have a textbox with a laeb for it and a checkbox.i need to disable the textbox as well as label when checkbox is checked.it is working in IE but not in FF.plz check...
4
by: blad3runn69 | last post by:
ms 97 howto call from a label box? thank you :) Sub Form_Current() Dim curAmntDue As Currency, lngBlack As Long Dim lngRed As Long, lngYellow As Long, lngWhite As Long If Not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.