Results 1 to 5 of 5
  1. #1
    Gizmodo is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Nov 2012
    Posts
    17

    Help with syntax

    Hey all,

    Trying to pull dates between a 3 year period where beginning date is 4/31/(Current Year - 3 years) and 3/31/(Current Year)... this is what i have come up with...

    WHERE ([County Master List].[Date Opened]) between #4/1/(datepart("yyyy",now()-3))# and #3/31/(datepart("yyyy",now()))#

    I get a syntax error

    any suggestions or new methods?



    Thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I prefer to use the DATESERIAL function to build dates. See: http://www.techonthenet.com/access/f...dateserial.php

  3. #3
    Gizmodo is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Nov 2012
    Posts
    17
    Perfect Thank you....

    Came up with this

    WHERE [County Master List].[Date Opened] between DateSerial((datepart("yyyy",now()))-3, 4, 1) and DateSerial((datepart("yyyy",now())), 3, 31)

    One more question though?

    Would it be possible to insert and iff statement within this where clause that would pull the current month and depending on if the month is December change the formula to the following:
    WHERE [County Master List].[Date Opened] between DateSerial((datepart("yyyy",now()))-2, 4, 1) and DateSerial((datepart("yyyy",now())), 3, 31)

    Basically to subtract 2 years instead of three

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I actually prefer
    Code:
    WHERE [County Master List].[Date Opened] between DateSerial(year(now())-3, 4, 1) and DateSerial(year(now()), 3, 31)
    over
    Code:
    WHERE [County Master List].[Date Opened] between DateSerial((datepart("yyyy",now()))-3, 4, 1) and DateSerial((datepart("yyyy",now())), 3, 31)
    Would it be possible to insert and iff statement within this where clause that would pull the current month and depending on if the month is December change the formula to the following:
    WHERE [County Master List].[Date Opened] between DateSerial((datepart("yyyy",now()))-2, 4, 1) and DateSerial((datepart("yyyy",now())), 3, 31)

    Basically to subtract 2 years instead of three
    Try:
    Code:
    WHERE [County Master List].[Date Opened] between DateSerial(year(now())-IIf(Month(Now())=12,2,3), 4, 1) and DateSerial(year(now()), 3, 31)

  5. #5
    Gizmodo is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Nov 2012
    Posts
    17
    Got you...makes sense...code looks alot "cleaner" and easier to understand

    Thanks again

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

Similar Threads

  1. Help with syntax
    By accesskid in forum Forms
    Replies: 3
    Last Post: 06-02-2011, 05:14 AM
  2. SQL syntax
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 05-04-2011, 08:32 AM
  3. Help with syntax
    By GWB in forum Queries
    Replies: 4
    Last Post: 01-26-2011, 03:33 PM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Please help SQL Syntax
    By jordanturner in forum Access
    Replies: 4
    Last Post: 09-02-2010, 08:05 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