Label font color changes when clicked

kidron

New member
Local time
Yesterday, 22:41
Joined
Sep 12, 2009
Messages
2
Hi,
I am developing an access database at work. I would like know if there is anyone who might know how you can program a label to change color when the user clicks on the label?:)
 
To my knowledge, labels don't have events. So clicking on the label won't do anything. However, you can change the border color of the label when the enter event occurs or the click event occurs for the control associated with that label.

The examples below are for highlighting the border color of a label of a the check box. To change the font color, you can change "CTRL.bordercolor" to CTR.forecolor". Note, one of the label properties needs to be set to "flat". Also you need a "wide" border so that you can see the border color. Changing the border color of the label helps the user see which is the active control. Of course the code below will probably require tweaking for your specific use.

PS: Credit for this solution belongs to gemma-the-husky and Rural Guy on this forum who provided the assistance that I needed.


Code:
Public Sub Form_Open(Cancel As Integer)
       For Each CTRL In Me.Controls
        If CTRL.ControlType = acLabel Or CTRL.ControlType = acTextBox Then
            CTRL.BorderStyle = 1
            CTRL.BorderWidth = 4
            CTRL.BorderColor = FormBackclr
            End If
        Next CTRL   
End Sub

When you enter the control associated with the label, a border color is activated on the label.

Code:
Private Sub carteret_Enter()
    Call Enter_Option
End Sub

Code:
Sub Enter_Option()
    OptionNameStr = Me.ActiveControl.Properties("name")
    For Each CTRL In Me.Controls
       If CTRL.ControlType = acLabel Then
           If CTRL.Parent.Name = OptionNameStr Then
               LabelNameStr = CTRL.Properties("name")
               CTRL.BorderColor = Borderclr
               End If
           End If
        Next CTRL    
End Sub

When you exit the control, the label has to be reset to the back color.

Code:
Private Sub carteret_Exit(Cancel As Integer)
    Call Exit_Option
End Sub

Code:
Sub Exit_Option()
    OptionNameStr = Me.ActiveControl.Properties("name")
    For Each CTRL In Me.Controls
       If CTRL.ControlType = acLabel Then
           If CTRL.Parent.Name = OptionNameStr Then
               LabelNameStr = CTRL.Properties("name")
               CTRL.BorderColor = FormBackclr
               End If
           End If
        Next CTRL
End Sub
 
Last edited:
Labels have events if they are not associated with other controls.
 
Hi,
I am developing an access database at work. I would like know if there is anyone who might know how you can program a label to change color when the user clicks on the label?:)

try this on for size:
PHP:
controlname click()

me.controlname.forecolor = "#FFFFFF"
 
Me.ControlName.ForeColor = "&HFFFFFF"
 
Awesome, that's exactly what I'm looking for. However I need to have the color reset to the original set color when the user starts a new record. Any help with that?
 
Awesome, that's exactly what I'm looking for. However I need to have the color reset to the original set color when the user starts a new record. Any help with that?

modify your onclick event to:
Code:
TempColor="&OriginalColorNumber" 
Me.ControlName.ForeColor = "&HFFFFFF"
Then on your exit event
Code:
Me.ControlName.ForeColor=TempColor

TempColor will need to be a public variable for the form.
 
Kidron.

You will need to give a little more information about when you want the label to revert back to its original colour.

Reverting on a new record won’t work if a global variable is used because it would revert to black if Access is closed and re-opened.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom