Results 1 to 7 of 7
  1. #1
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100

    ?How to flag row based on date value?

    Hello



    I have a field (Clock in - Data Type = Short Text) where that tells me the date and time an employee clocked in, ex. 03/20/2022 8:16:34 AM. I created a field to extract the date
    Code:
    DateClockedIn: Format(left([Clock in],10),"General Date"
    which returns 03/20/2022 * I have also tried mm/dd/yyyy where I have "General Date".

    I then create another field
    Code:
    Flag: IIF([DateClockedIn] < #03/20/2022#,"True","")
    . This field only returns "True" on fields where the month is March, it doesn't flag all other dates that were before March 20, 2022. I am convinced it's on how I extracted the date (I've always had trouble properly formatting dates when I extract them to read as an actual date).

    Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Issue is because [DateClockedIn] is not really a date/time value, it is just a string. Format function returns string. Have to convert to date/time value.

    IIf(CDate([DateClockedIn]) < #03/20/2022#,"True","")

    Why is the raw data in a text field instead of date/time type?

    Advise not to use spaces in naming convention.
    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
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    Thank you - I never had to use that expression; it worked. So CDate should be used when we have a date that is a string and want to have set a criteria?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you want a value to be treated as a date/time for chronological sorting/filtering, yes, convert to date/time.

    Must understand that a true date/time value is really a double number. The MM/DD/YYYY hh:nn:ss structure that is displayed is just a format.
    Last edited by June7; 03-26-2022 at 10:26 AM.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Could also try DateValue?
    Code:
    ? DateValue(Now())
    26/03/2022
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Dang, forgot about DateValue again.

    DateClockedIn: DateValue([Clock In])

    Flag: IIf(DateClockedIn < #3/20/2022#, "True, "")

    or just

    Flag: IIf(DateValue([Clock In]) < #3/20/2022#, "True", "")
    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
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    Thank you both - this helped a lot.

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

Similar Threads

  1. Red Flag warning bsed on Membership date
    By RustyRick in forum Access
    Replies: 5
    Last Post: 07-20-2016, 10:31 AM
  2. flag duplicates based on duplicate values
    By dleger00 in forum Queries
    Replies: 3
    Last Post: 07-13-2014, 08:32 PM
  3. How to flag a warning
    By SamCrow in forum Queries
    Replies: 3
    Last Post: 01-12-2014, 10:52 AM
  4. Date flag
    By glasgowlad1999 in forum Forms
    Replies: 5
    Last Post: 02-15-2011, 06:13 AM
  5. flag in access
    By bold01 in forum Access
    Replies: 9
    Last Post: 02-03-2011, 11:08 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