Results 1 to 7 of 7
  1. #1
    JohanG is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    14

    Conditional Formatting of a Text Field containing characters A-Z

    Greetings Experts,



    I want to highlight a field [ProductCode] defined as Text on a listed sub form if any of the listed ProductCode values contain any alpha characters or are not 6 characters in length.

    Our "ProductCodes" are typically numerical like values such as 09876 saved in said Text field; I want to highlight any fields that do not conform to 6 numerical values.

    For Example:

    If the value is something like "R34561" (contains an alpha character) or "678" (less than 6 characters) or "abc4321" (contain multiple alpha characters and/or contain more than 6 characters) or "6321452" (more than 5 characters/numerals) it must be highlighted.

    If the value contains any numerical digit 0-9 and Length = 6 then the field must NOT be highlighted (e.g. 654328)

    I have tried adding the conditional formatting expression:

    If Like "*[A-Za-z]*" Or Len([ProductCode])<>6

    But using the above also formats valid Product Codes such as "654328" (which it shouldn't)



    Not sure where I'm missing the plot...Please assist?

    Much appreciated!
    Last edited by JohanG; 07-13-2023 at 04:02 AM.

  2. #2
    JohanG is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    14
    I have managed to accuire the correct results by adding the following expression:

    (Asc([ProductCode])>64 And Asc([ProductCode])<91) Or Len([ProductCode])<>6

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by JohanG View Post
    I have managed to accuire the correct results by adding the following expression:

    (Asc([ProductCode])>64 And Asc([ProductCode])<91) Or Len([ProductCode])<>6
    Keep in mind that it won't catch letters "a-z" though
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    JohanG is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    14
    So I should probably amend the expression to: (Asc(UCase([ProductCode]))>64 and Asc(UCase([ProductCode]))<91) or Len([ProductCode])<>6

    Do you agree?

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    I think you might need the following but I haven't tested it:

    ((Asc([ProductCode])>64 And Asc([ProductCode])<91) OR (Asc([ProductCode])>97 And Asc([ProductCode])<122)) Or Len([ProductCode])<>6
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe:

    Not IsNumeric([ProductCode]) Or Len([ProductCode])<>6

    or

    IsNumeric([ProductCode]) = False Or Len([ProductCode])<>6
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    JohanG is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2022
    Posts
    14
    Hi June7,

    IsNumeric([ProductCode]) = False Or Len([ProductCode])<>6

    Works perfectly :-)

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: 5
    Last Post: 03-20-2018, 06:52 PM
  3. Replies: 5
    Last Post: 05-22-2017, 01:34 PM
  4. Replies: 7
    Last Post: 03-03-2014, 01:36 PM
  5. Replies: 1
    Last Post: 04-26-2012, 08:31 PM

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