473,626 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change label color of checkbox when checked?

37 New Member
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
5 13835
NeoPa
32,567 Recognized Expert Moderator MVP
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 New Member
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,567 Recognized Expert Moderator MVP
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 New Member
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,567 Recognized Expert Moderator MVP
You seem to be misunderstandin g 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
11454
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. With regular input such as textboxes, everything lines up fine. The problem I'm having is that I have an unordered list of checkboxes, and only the first item will line up with the label. The additional checkboxes and their labels end up being...
7
2939
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 unchecked. I'm using the following construct: document.cookie = "cpceRememberLoginCookie="+document.getPage1.rememberLogin.value+"; expires=Thr, 01-Jan-2015 00:00:00 GMT"; The actual checkbox value passed in the <form> POST reflects the actual...
2
2084
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, etc What I'm looking for is how to determine what checkbox was selected from the three checkbox web controls and have the selected checkbox(es) display in a label
7
2270
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 Datagrid that will fire off when the Checkbox is changed? regards /Lars
1
3773
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 say's "process". I want to LOOP through each datalist entry and see if the user checked the check box. Simple. I wrote the code, but the checked value is ALWAYS False. Any ideas? Here's the code...
16
7263
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;" onclick="ClickBoxClick('IsProd');"> <input type="checkbox" name="IsProd" value="1" /> Is a Product </span>
1
1633
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 Purple (visited)? Thanks
3
2228
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 protected void lbASurgery_Click(object sender, EventArgs e) { multiView.ActiveViewIndex = 0; }
2
1951
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 my code and tell me a solution <td id='abc' name="xyz"> Text </td> <Input type="text" readonly name="abc1" style="width:165px;" size = "20" > in javascript my code is
4
3827
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 IsNull(Me!txtPastDue.Value) Then curAmntDue = Me!txtPastDue.Value Else
0
8268
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.