Results 1 to 6 of 6
  1. #1
    TonyB is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16

    Question Using Between with iif isnull

    Hi,

    When users enter a date form ("orderdatefrom") and a date to ("orderdateto") on a form, they click the "Run Query" button and the query returns all results of orders placed within that date range. To do this, I use the following statement under the "OrderDate" field in my query:

    Between [forms]![frmProjReq]![orderdatefrom] And [forms]![frmProjReq]![orderdateto]

    This works fine, but in order for it to work, users are forced to enter a date range (otherwise the query returns no results because nothing is entered). How do I change it so that if no dates are entered, then the query displays all the records in the table? I have tried:

    Iif(isnull([forms]![frmProjReq]![orderdatefrom] And [forms]![frmProjReq]![orderdateto]),[tblReqOrders].[OrderDate],Between [forms]![frmProjReq]![orderdatefrom] And [forms]![frmProjReq]![orderdateto])



    But this does the opposite - it shows all data, but only if nothing is entered in the "orderdatefrom" and "orderdateto" boxes on my form. Access also changes the statement for some reason.

    I've managed to work around this by using VBA to tell the form to input dates from 01/01/1900 to 31/12/2999 into the "orderdatefrom" and "orderdateto" boxes if they are are currently null, and then use the simple "between" statement at the top of this post, in the query. However, it's a bit messy and I think it would be better if I didn't have to do this.

    Thanks

  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,640
    How about

    Nz([forms]![frmProjReq]![orderdatefrom], #01/01/1900#)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TonyB is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16
    Thanks, but it constantly returns no values at all when I tried that statement, regardless of whether anything is entered or not.

  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,640
    Did you use it with Between and the other textbox with the appropriate date value?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    TonyB is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    Oxfordshire, UK
    Posts
    16
    Awesome thanks!

    Indeed the following worked:

    Between Nz([forms]![frmProjReq]![orderdatefrom],#01/01/1900#) And Nz([forms]![frmProjReq]![orderdateto],#01/01/2099#)

    Cheers man!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help!
    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. IF IsNull set width to 0
    By Casey Sanders in forum Reports
    Replies: 7
    Last Post: 01-30-2013, 08:16 AM
  2. If Date IsNull
    By burrina in forum Forms
    Replies: 6
    Last Post: 01-10-2013, 07:23 PM
  3. If IsNull Value, Then need to be Zero
    By burrina in forum Forms
    Replies: 2
    Last Post: 11-18-2012, 02:53 AM
  4. IsNull
    By JJCHCK in forum Programming
    Replies: 3
    Last Post: 09-09-2011, 07:57 AM
  5. IsNull question
    By Simon Sweet in forum Access
    Replies: 4
    Last Post: 12-22-2007, 04:33 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