checkbox result highlights text fields in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • awojciehowski
    New Member
    • Feb 2008
    • 21

    checkbox result highlights text fields in form

    Can anyone provide me with some guidance on the following issue?

    I want to have a checkbox on a form to be used as a conditional formatting trigger to highlight the background color of multiple text boxes on the rest of the form. For example if someone were to click on the checkbox it would automatically turn the background color of several text boxes red.

    I want it to be used so when someone files through the records they can easily identify those special records.

    Any help would be greatly appreciated!!!

    Adam
  • MindBender77
    New Member
    • Jul 2007
    • 233

    #2
    In the OnClick event of the check box, you can do something like this:
    [code=vb]
    If CheckBox.Enable d = True Then
    TextBox1.BackCo lor = RGB(255, 0, 0) 'This is Red
    Else
    TextBox1.BackCo lor = RGB(0, 0, 0) 'This is White
    End If
    [/code]

    Hope this Helps,
    Bender

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Not sure that the checkbox approach is best, but even so - you can attach very simple code to the on-click event of the checkbox to change the background colour of whatever controls you wish on your form. Here is an example that changes the background of two controls, using lightyellow as the 'checked' background colour (I would not use red because it makes the contents of the control unreadable to the eye). You can change the colours by changing the colour values and constant names as you wish.

      Code:
      Private Sub Check0_Click()
          Const LightYellow = 10092543
          Const White = 16777215
          If Check0 Then
              Me.Text2.BackColor = LightYellow
              Me.Text4.BackColor = LightYellow
          Else
              Me.Text2.BackColor = White
              Me.Text2.BackColor = White
          Endif
      End Sub

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Also note that the solutions offered here will only change the background colors when the checkbox is checked! In order for these changes to be persisted, i.e. in order for the changed colors to remain the same for any given record, you'll have to include the same code in the Form_Current event.

        Welcome to TheScripts!

        Linq ;0)>

        Comment

        • awojciehowski
          New Member
          • Feb 2008
          • 21

          #5
          Thanks everyone for your input. However, after some more research I found my solution in the conditional formatting option.

          I chose the "Expression Is" option and then used the following code for the each text box I wanted changed when the specific text box was checked.

          [NameofCheckBox]=True

          Then all I had to do is choose the background color...

          Good to go.

          I hope this posting helps others!

          Comment

          • justforthis
            New Member
            • Nov 2011
            • 1

            #6
            Thesecond solution worked fine for my fields. My Checkbox is called CheckBox13, and my textboxes are TextBox1 and so forth.
            The code looks like this:
            Code:
            Private Sub CheckBox13_Click()
             Const LightYellow = 10092543
                Const White = 16777215
                If CheckBox13 Then
                    TextBox1.BackColor = LightYellow
                    TextBox11.BackColor = LightYellow
                    TextBox12.BackColor = LightYellow
                    TextBox13.BackColor = LightYellow
                    TextBox14.BackColor = LightYellow
                    TextBox15.BackColor = LightYellow
                    TextBox16.BackColor = LightYellow
                    TextBox17.BackColor = LightYellow
                    TextBox18.BackColor = LightYellow
                    TextBox19.BackColor = LightYellow
                Else
                    TextBox1.BackColor = White
                    TextBox11.BackColor = White
                    TextBox12.BackColor = White
                    TextBox13.BackColor = White
                    TextBox14.BackColor = White
                    TextBox15.BackColor = White
                    TextBox16.BackColor = White
                    TextBox17.BackColor = White
                    TextBox18.BackColor = White
                    TextBox19.BackColor = White
                End If
            End Sub
            I could not figure out what the solution suggested by awojciehowski was, but solution two did solve my problem easily!

            Thanks!
            Last edited by NeoPa; Nov 12 '11, 12:26 AM. Reason: Added mandatory [CODE] tags for you

            Comment

            Working...