Results 1 to 6 of 6
  1. #1
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60

    Conditional Formatting form field based on Yes or No

    Hi

    Does anyone know a neat way to highlight a field on a form if it has Yes or No in it? Obvs Fill Green if yes, Fill Red if no?

    I currently have this which a picked from a Google search. I can get it to go Green if yes not not Red if no.

    InStr([MyFieldName],"Yes")>0



    but if I add a second condition for No, it doesn't seem to like it.

    Any hints?

    Thanks

  2. #2
    JoeM is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    3,904
    You added a second rule, and didn't overwrite the first one, right?

    What does your data look like?
    Note that InStr is case-sensitive. So "No" is not the same as "no".
    Also note that you could get false positives, if it is part of a larger word (i.e. like "Snow", "Now", etc).

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Note that InStr is case-sensitive. So "No" is not the same as "no".
    Not necessarily true. If the parameter is omitted, it defaults to your Option Compare statement. That may or may not be binary. I'd say in most cases it is not.
    @Raddle, post more than one line of code so we can see what you have. Please use code tags and indentation for more than a few lines (# on posting toolbar). Is the yes or no buried within other words or is it a single value?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Thanks for the hints and the time to reply.

    So embarrassingly that is the whole 'code' ....

    In form design, I select the field and choose conditional formatting and then add a rule and paste that in. Obvs the field name is real in my version.

    And this works for a single condition. However I need it to work to for when there is a 'No' in the field value.

    Yes I added a second rule with the No condition and that does not solve it.

    ************ having looked again at the case sensitive element, with the second rule, that seems to solve it. Thank you *********

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    You will also turn the field red if it contains the word "Notes", so add a space to the test string?
    I incorrectly assumed you were using vba to do the CF.

    EDIT - In fact, with just a trailing space I suspect a string like " The rhino was huge." would also turn red, so a leading and trailing space perhaps.
    Unfortunately you didn't answer if the yes/no was a single value or was contained in a sentence/string.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    My bad and thank you for coming back to me ...

    It should be either Yes or No although it is a short text field, so there could indeed be anything in there about rhinos too.

    Will try to frame my questions more accurately going forward. Thanks for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-13-2020, 12:19 AM
  2. Replies: 4
    Last Post: 06-12-2018, 03:37 PM
  3. Conditional Formatting based on result
    By Skyace00 in forum Reports
    Replies: 1
    Last Post: 01-13-2016, 05:19 PM
  4. Conditional Formatting based on another field - Part II
    By Harley Guy in forum Programming
    Replies: 8
    Last Post: 10-17-2013, 12:46 PM
  5. Replies: 5
    Last Post: 10-15-2013, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums