Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Text64 change color if

    Here is my code but it does not work. I want it to change the color of th text box based upon whether it is a true or false.True showing Green and False showing Red. What do I need to change and on what event do i place this, when the form loads or what ? Right now it is on the forms load event.

    If [Text64].Value = True Then [Text64] = vbGreen

    If [Text64].Value = False Then [Text64] = vbRed

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Too many possibilities here; we need more information in order to help.
    1. Is Text64 Bound or Unbound?
    2. Is it a Checkbox that is Bound to Yes/No Field, or a Textbox/Combobox where the users enter/select the Values of "True" or "False?"
    3. Is this a Single View, Continuous View or Datasheet View Form?

    Everything else aside, Form_Load is the wrong event for this code. With the code in this event, the Conditional Formatting, for all Records, will be based on the Condition in the first Record. Depending on the answer to Question #3, you may not be able to use code at all, but will need to use the Conditional Formatting off of the Format Menu or Ribbon.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2011
    Posts
    413

    Text64

    It is an bound text box with a yes/no value that is on my form.It's control source is Financial. This is really a duplicate of the forms other check box bound control which has its control source set to Financial as well. I just wanted it displayed differently at the top of the form with criteria.
    Hope this makes it clear,sorry for my vague question.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In Form Design View
    1. Right-Click on the Text64 Control
    2. Click on Conditional Formatting
    3. In the Conditional Formatting Window, going from Left-to-Right
    4. Under Condition1 select Field Value Is
    5. In the next box select Equal To
    6. In the next box type in “yes” (with the Quotation Marks)
    7. Use Icons to Format as you want it if Text64 = “Yes”
    8. Click on Add>>
    9. Go back to the far Left of the row
    10. Under Condition2 select Field Value Is
    11. In the next box select Not Equal To
    12. In the next box type in“yes” (with the Quotation Marks)
    13. Use Icons to set your Format if Text64 <> “Yes”
    14. Click on OK

    You still speak of this being a Checkbox at one point and a Textbox at another point. If the Financial Field is defined, in the TableDefs, as a Text Datatype, use the above.

    If, however, Financial is defined at the Table level as a Yes/No Datatype, replace ‘yes’ in Line # 7 and Line # 13, above, with -1

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    your original code would have worked if you had set the value of the relevant property. what you did do was assign the value of the vb colour constants to the control

    instead of
    Code:
    If [Text64].Value = True Then [Text64] = vbGreen
    If [Text64].Value = False Then [Text64] = vbRed
    Code:
    If [Text64].Value = True Then Text64.backcolor = vbGreen
    If [Text64].Value = False Then Text64.backcolor = vbRed
    ..you don't need the square brackets if there are no spaces in the control name

    however that code would only set a colour if it was one those two options
    instead
    Code:
    If [Text64].Value = True Then
      Text64.backcolor = vbGreen
    else
      Text64.backcolor = vbRed
    endif
    would explcitly always set a vale

    Missingling is absolutely correct to use the conditional formatting if it was a continuouis form (it has the added advantage that you don't have to put the same code (or call to a function) that sets the colours is several places. however it can be a sledgehammer to crack a nut, and it only allows you to set the properties of that single control. if you wanted to set the colours of several controls then using the conditional formatting you have to repeat the same code in each affected control. if you are using a report or (single) form then you can do the same effect using VBA. bear in mind though you cannot set such properties in continuous fors using VBA.

    be wary ot comparing to 'yes' / 'no' its better to use the uynerdlyign dataype.. if its a boolean value then using vbtrue vbfalse is the correct way to go.
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by healdem View Post
    your original code would have worked if you had set the value of the relevant property. what you did do was assign the value of the vb colour constants to the control
    Not with the code placed in the Form_Load event,as the OP is/was currently doing. As I said, that would format all Records according to the Condition present in the first Record displayed. The corrected code would have to be in the Form_Current event.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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