Results 1 to 8 of 8
  1. #1
    athanera is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5

    How to apply conditional formatting to date values in a calculated text field

    Hi! I am fairly new and appreciate any help here! I am trying to apply conditional formatting in a form to highlight any records in a field called ExpirationDate2 that will expire before 11/30 of the current year. The expression I am using is: Value < CDate("11/30/" & Year(Date$()))

    While that expression is working just fine in other date fields, ExpirationDate2 is formatting dates incorrectly. I suspect this is because it is a text field that is actually calculated in a query, since not all records expire (I made a separate field for those called "Open"). This is the expression from the query:
    ExpirationDate2: IIf([Open]=False,[ExpirationDate],"Open")



    Is there a way to specify that conditional formatting should only apply to certain values (those that look like dates, even though they are stored as text)?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe use the IsDate() function.
    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.

  3. #3
    athanera is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5
    Thanks for the reply! That sounds like what I need- but the expression I made is still not picking out the right dates:
    IsDate([ExpirationDate2]) And ([ExpirationDate2]<CDate("11/30/" & Year(Date$())))

    Any reason why this would not work? Some of the right dates are highlighted, but so is 1/1/2023...

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Did you select Expression Is?

    Try:

    IIf(IsDate([ExpirationDate2]), [ExpirationDate2]<CDate("11/30/" & Year(Date())), False)
    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.

  5. #5
    athanera is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5
    Yep, Expression Is was selected. I had tried the IIF expression as well- but it does not result in any cells being highlighted. Seems like it should work. Running IsDate all by itself correctly highlighted all the dates, and the rest of the expression was used successfully elsewhere in the database. For fun, I built another form in case corruption was the cause of this funkyness, but no dice there either. I wonder what else is at play.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I tested expression on data that mixes number and string values in a text field. Used IsNumeric. It works.

    My suggestion does have a typo. In case you didn't catch, missing /. I corrected the post.

    If you want to provide db for analysis, follow instructions at bottom of my post. Identify object involved.
    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
    athanera is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5
    This database is chock full of personal information, so I am downsizing and disguising enough of it to post. Looks like it won't be ready until Monday. I appreciate your time and have a wonderful weekend!

  8. #8
    athanera is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5
    Found the solution! I definitely don't understand why, but when I added a new field to the form, and used the exact same expression that I used in the query, the conditional formatting--with my initial expression--works! So, instead of adding the calculated field from a query, I just performed that calculation in the control source of a new field... and now Access seems to recognize dates just fine, even though the expression gives a mix of dates and text. So strange.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-06-2013, 02:12 PM
  2. Replies: 3
    Last Post: 08-02-2013, 12:18 PM
  3. how to apply Conditional Formatting in run time
    By selvakumar.arc in forum Forms
    Replies: 7
    Last Post: 07-03-2013, 12:41 PM
  4. Replies: 1
    Last Post: 04-26-2012, 08:31 PM
  5. Replies: 0
    Last Post: 03-14-2011, 08:38 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