Need Help Writing Query Expression that Includes IsNull Or with dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Adelestrat
    New Member
    • Aug 2014
    • 4

    Need Help Writing Query Expression that Includes IsNull Or with dates

    I'm trying to have a query return "due by 9/8/14" if the entry in a field is blank or has a date before 9/8/14, or return "valid through (date)" if the date in the field is after 9/8/14. Here's how I've written the expression:

    Code:
    MedWords=IIf([Grace] IsNull Or <9/8/14, "due 9/8/14", "valid through [Grace]")
    What am I doing wrong?
    Last edited by zmbd; Sep 2 '14, 09:50 PM. Reason: [z{added code tags}]
  • Adelestrat
    New Member
    • Aug 2014
    • 4

    #2
    Never mind, I figured it out! It works when I wrote it this way:

    Code:
    IIf(IsNull([Grace]) Or [Grace]<#9/8/14#, "due 9/8/14", "valid through " & [Grace])
    Last edited by zmbd; Sep 2 '14, 09:50 PM. Reason: [z{added code tags}]

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Try this :
      Code:
      MedWords=IIf(Nz([Grace],#1/1/2014#)<#9/8/2014#,'due 9/8/2014','valid through '+[Grace])

      Comment

      • Adelestrat
        New Member
        • Aug 2014
        • 4

        #4
        Thanks, NeoPa. That didn't work. As I mentioned in my second post, I finally found the right way to do it which was:

        Code:
        IIf(IsNull([Grace]) Or [Grace]<#9/8/14#, "due 9/8/14", "valid through " & [Grace])
        Last edited by zmbd; Sep 2 '14, 09:51 PM. Reason: [z{added code tags}]

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Please share how it didn't work. If all the details we have from you are correct then I fail to see how that were possible.

          Your approach certainly should work too - but I wouldn't describe it as the right way. You certainly wouldn't use IsNull() in SQL for preference over [X] Is Null. Other than that I would generally look for a single check rather than two if possible.

          I'm very interested to hear how it is that my suggestion failed mind you.

          Comment

          • Adelestrat
            New Member
            • Aug 2014
            • 4

            #6
            I see that my expression builder was trying autocorrect your expression (by putting MedWords into brackers). When I manually return yours to what you actually wrote, it does work.

            Thanks so much.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32661

              #7
              No problems :-)

              Don't forget - your version works also. There is rarely ever only one right answer.

              Comment

              Working...