Results 1 to 15 of 15
  1. #1
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318

    Syntax of a Formula using Date Part


    I think I have the syntax wrong in the date part area. Can you help?

    = IIf(IsNull([Space](IIf([FSL]=4,IIf([CountOfInsp_Date]<DatePart("ww",date()*2),"Under",IIf([CountOfInsp_Date]=<DatePart("ww",date()*2.5),"On Target", "Over"))

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Offhand I'd say the syntax error is with the IsNull at the beginning, but it makes no sense to multiply the date by 2 or 2.5. What are you trying to achieve?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    If [space] is null and the [FSL] = 4 and you took the week number (i.e. 2 for Jan 11) and times it by 2 (which gives you 4) and the count is less than that then they are under their count. If you times the week by 2.5 (giving you 5 in our example) and they greater than 4 but =< 5 then they are on target, otherwise they are over. I hope this makes sense.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    You'd want to get the week, then multiply by 2. You're multiplying before getting the week.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    By the way, what's going to happen later in the year when the week is 30 or 40?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    So it should be <DatePart("ww",date())*2, "In week 52 they should have 104 or more in their count.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Yes; does it work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    it still gives the syntax error. how is the IsNull wrong?

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    The parentheses aren't closed, and it runs right into the IIf() following it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    Changed it to this but still getting the syntax error.

    = IIf(IsNull([Space]),(IIf([FSL]=4,IIf([CountOfInsp_Date]<DatePart("ww",date())*2,"Under",IIf([CountOfInsp_Date]=<DatePart("ww",date())*2.5,"On Target", "Over")))

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    You have an extra opening parentheses before the second IIf(). I think you just needed to flip that one around, but now it should be deleted. You also start 4 IIf() functions but only appear to close 3.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    It's still giving the error

    =IIf(IsNull([Space]),IIf([FSL]=4,IIf([CountOfInsp_Date]<DatePart("ww",date())*2,"Under",IIf([CountOfInsp_Date]=<DatePart("ww",date())*2.5,"On Target","Over"))))

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    I don't think you ever provide a False argument for the first IIf (or the second now that I think about it).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318
    I broke it down to try to get the details right but I'm still missing something. Please see the attached.
    Attached Files Attached Files

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    You've added some new conditions to the mix? Personally, this is getting too complicated to do with a nested formula like this. I'd create a public function that accepts Space, FSL and the count as inputs and returns the desired value. It will be much easier to create the logic there, and easier to update if (when?) the logic changes in the future.
    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. Changing the century part of the date.
    By Chet in forum Queries
    Replies: 2
    Last Post: 05-13-2012, 08:27 PM
  2. IIF formula in an unbound text box using date()
    By probablyjoel in forum Forms
    Replies: 3
    Last Post: 04-20-2012, 12:03 PM
  3. Getting Just the Date part of Date/Time field
    By GaryElwood in forum Reports
    Replies: 7
    Last Post: 09-28-2011, 09:58 AM
  4. Date Syntax
    By Alex Motilal in forum Forms
    Replies: 3
    Last Post: 10-28-2010, 06:26 AM
  5. Complex Date Comm/Amt Formula
    By JLongo in forum Programming
    Replies: 0
    Last Post: 11-21-2008, 10:24 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