Results 1 to 8 of 8
  1. #1
    espinosaja is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    4

    Red face Access-comparing Dates

    I have a table with dates of surveys; the next column adds 5 years to that date. the 3rd column compares the two dates. if the second column is less than todays date it will give a message if not it will insert the date from the 2nd column

    ex.
    A:survey date
    B(Expr1):survey date + 5 years
    C: if B < 2/6/2010 then "Turn in new Survey" if B>"2/6/2010" then "B"

    Survey Message: IIf(([Expr1])<"2/6/2010","PAST DUE, PLEASE SUMBIT A NEW SURVEY WITH PICTURES BY Feb. 6, 2012",[Expr1])

    value of Ex.

    A:3/5/2001


    B:3/5/2006
    C:Turn in new Survey
    Great! this works fine

    But:

    A:12/12/2008
    B: 12/12/2013
    C:s/b 2/12/2013 *

    *but it compares the 1 (12-December) with 2 and it thinks it's smaller and it puts the message! how do I compare values or the whole date?
    Last edited by espinosaja; 11-09-2011 at 03:18 PM. Reason: format

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Presume you mean you have a query doing these calcs, not a table.
    The criteria date is shown as hard code. Should that be the current date?

    Syntax for B and C wrong.
    Without DateAdd function, adding a number to a date defaults to day unit. Don't see how B could be working.
    B: DateAdd("yyyy",5,[survey date])
    C: IIf([B] < Date(), "Turn in new Survey", [B])

    The revised due date is also hard code. Should that be calculated?
    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
    espinosaja is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    4
    Sorry here are the actual formulas:

    B: Expr1: DateAdd("yyyy",5,[survey])

    So are you saying in C: instead of "2/6/2010" I should put Date(2/6/2010)?

  4. #4
    espinosaja is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    4
    I'm trying to post the table so you can see it!

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    No, Date() is a function with no arguments. It will return the current date. Now() will return current date and time. Test them in the VBA editor immediate window with: ?Date()
    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.

  6. #6
    espinosaja is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    4

    Date comparison

    Still having same date comparison problem.

    if a date in Col A is 2/6/2010 and in Col B is 12/6/2014

    I am comparing to see if the date in Col B is less than the date in col A. if so, then a message should pop up, and if not then it should return with the date in col. B.

    well, when it returns it compares the digits from left to right so it considers 1 (of 12) less than 2!

    here's my expression:
    Survey Message: IIf(([Expr1])<"2/6/2010","PAST DUE, PLEASE SUMBIT A NEW SURVEY WITH PICTURES BY Feb. 6, 2012",[Expr1])

    HELP!!

    Thank you

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    If [EXPR1] is a date then change "2/6/2010" to #2/6/2010#

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Good catch Ray.

    Use apostrophe delimiters for text and # for dates, numbers need none.
    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.

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

Similar Threads

  1. Comparing dates
    By shanky365 in forum Queries
    Replies: 2
    Last Post: 10-26-2011, 01:28 AM
  2. Replies: 4
    Last Post: 09-24-2010, 11:23 PM
  3. Comparing fields in Access
    By flames8889 in forum Queries
    Replies: 2
    Last Post: 04-20-2010, 11:55 AM
  4. Comparing Dates And Matching Quantities
    By chrisleng in forum Programming
    Replies: 0
    Last Post: 02-23-2010, 10:50 AM
  5. Comparing Part Quantities According to Dates
    By rochy81 in forum Reports
    Replies: 6
    Last Post: 05-19-2009, 09:11 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