Results 1 to 9 of 9
  1. #1
    BillG is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    14

    how to make a specific date the year a variable???

    I have in a query a complex formula that has -
    "Iif(date=#1/1/2013#,true,false)"
    and my output in my formula is correct.

    But I need to make the year = a variable not a constant or omit the year entirely.



    I tried Iif(date=#1/1/Year(Date)#,true,false) and it gives me an error invalid date format.

    I tried Iif(date=#1/1#, true, false) omitting the year and it gives the error invalid date format.

    I really don't even need the year. I just need a Iif statement if the date is 1/1 then do this.

    But I can't figure out a simple solution, yet it seems pretty simple.

    Anyone with an idea???

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would use the DateSerial() function to make the year a variable, or the Month() and Day() functions to ignore year.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    BillG is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    14
    Understood, but these formulas are long and complex and to use date serial or month day parameters is extremely adding to the length of the formulas which this scenario is in multiple formulas and queries which is why I was trying to keep it simple using #mm/dd/yyyy# or something similar.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Okay; good luck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Paul has given you good advice. Perhaps you could tell us in plain English WHAT exactly is the Purpose of the parameter query?
    Please show your parameter query SQL.

  6. #6
    BillG is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    14
    the purpose is that my queries if date is 1/1 rollback to previous month's data for the query and reports. but if 1/1/2013 (new year) the query can't rollback to the previous month because it is also a previous year. So I need to qualify if 1/1/Year(Date) as a variable I can then make it rollback correctly.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you want the previous month, which you didn't say before:

    'First of previous month
    DateSerial(Year(Date()), Month(Date()) - 1, 1)

    'Last of previous month
    DateSerial(Year(Date()), Month(Date()), 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    BillG is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    14
    I understand, but I need something only for 1/1/year.

    previous month January 1st is also a previous Year si I have to specify for 1/1/Year to use month December and previous year.

    All other 11 months first day, I have a working formula.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I guess I don't really understand the goal. What's the formula that works for the other 11?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2013, 10:12 AM
  2. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  3. Italicizing text after specific year
    By hawkins in forum Access
    Replies: 4
    Last Post: 10-05-2011, 03:28 PM
  4. variable returning 1990 for the year
    By TinaCa in forum Programming
    Replies: 3
    Last Post: 08-31-2011, 09:51 AM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 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