Results 1 to 14 of 14
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    backcolor in form field (2002)

    I am trying to change the backcolor of all the fields in a record depending on what the value is in one of the fields. Below is the code I was trying to use in the current event of the form, but what happens is that whatever the value is in the first record that seems to determine the color for all the rest of the records. I want each record to be decided separately. What am I doing wrong?

    Private Sub Form_Current()
    If Me.discipline = "math" Then
    Me.crsname.BackColor = RGB(153, 204, 255)
    Else
    Me.crsname.BackColor = RGB(255, 255, 255)

    End If
    End Sub

    Thanks for the help.

    Paul

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: backcolor in form field (2002)

    I assume that this is a continuous form. A continuous form actually has only one set of controls, if you change the background color (or font, or ...) of a control it will apply to all displayed records.

    If you want formatting depending on the data:
    - Select the control (in design view)
    - Select Format | Conditional Formatting...
    - Under Condition 1, specify Value Is, Equal To, "math"
    - Select the desired bak color.
    - Click OK.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    Thanks Han. I need a little more explanation. Not sure I know what you mean by select the control. What are you referring to when you say control? Do you mean the field where "math" appears?

    Thanks. Paul

  4. #4
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    Charlette- Your second sentence is confusing. I still do not know where to put the code to do what I want to do.

    Paul

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: backcolor in form field (2002)

    Open your form in design view.
    Locate the text box bound to the crsname field (it is probably named crsname too)
    Move your mouse pointer until it is over this text box.
    Click your left mouse button once (if you have switched your left and right mouse buttons, click the right mouse button once).
    If you have done it correctly, there will be black squares at the corners and halfway the edges of the text box. This indicates that you have selected the text box.
    Then click the Format menu, and select the Conditional Formatting entry.
    Follow the rest of the instructions from my first reply.

    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> Her name is Charlotte (and mine is Hans)

  6. #6
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    Now I understand. Had never used that procedure before. Got it to work.
    Now what is the best way to get all the rest of the fields in each record to change their backcolor based on the main field Discipline that has the value of math or sci.

    Thanks again

    Paul

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: backcolor in form field (2002)

    You can set conditional formatting for multiple text boxes at once:
    - Select the text boxes and/or combo boxes that you want to apply conditional formatting to, either by clicking on the first one, then Shift+clicking on each subsequent one, or by dragging a rectangle that covers the text boxes partially and/or combo boxes or entirely.
    - Take care not to include other controls such as labels, for you cannot apply conditional formatting to other controls than text boxes and combo boxes. You can deselect a control that you selected by mistake by Shift+clicking it.
    - When you have selected the correct text boxes and/or combo boxes, point to the Format menu and select Conditional Formatting...
    - The settings you specify will be applied to all selected controls.

  8. #8
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    Hans - still struggling with this.
    Do I set the conditioning formatting up on the discipline field first and then highlight all the fields or do I do I highlight all the fields and then do the conditional formatting.
    Not sure how to setup the conditional formatting to get all the fields to change color based on the discipline field.
    How do I configure the settings that they ask for in the conditional formatting screen.

    Thanks again. Sorry to keep coming back for help.

    Paul

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: backcolor in form field (2002)

    You don't need to select the discipline text box first.
    - Select all text boxes/combo boxes that you want to apply conditional formatting to, the way I described in my previous reply.
    - Select Format | Conditional Formatting...
    - Under Condition 1, select "Expression Is" from the first dropdown list.
    - In the box next to it, enter the following expression:

    [Discipline]="math"

    - Select the desired background color from the "paint bucket" dropdown box.
    - Click OK.

  10. #10
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    Getting closer- I was using the expression me.discipline="math"

    I set up the conditional formatting with expression is [discipline]="math" Set the backcolor.
    When I click Ok I get the message: You must specify criteria for all conditional formats.

    What am I missing?

    Pasul

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: backcolor in form field (2002)

    Apparently, you have clicked Add >> to add a section labeled Condition 2 (and perhaps Condition 3). You don't need those here. Click Delete... in the Conditional Formatting dialog, tick the check boxes for Condition 2 and Condition 3, but not for Condition 1, then click OK.

  12. #12
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: backcolor in form field (2002)

    It now works!
    The problem was I did not have the Default conditional formatting set.

    Thanks.

    Paul

  13. #13
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: backcolor in form field (2002)

    Fields are columns in a table. What is on the form is controls each bound to a field or unbound. When you click on the control, you select it.
    Charlotte

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: backcolor in form field (2002)

    Sorry about the typo in the second sentence. That definitely muddled the meaning. I can see that Hans is taking good care of you, so you don't need more input from me. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •