Results 1 to 6 of 6
  1. #1
    Join Date
    May 2019
    Posts
    65

    Using Between Operator when control is blank

    Hi,


    I'm using a query that has 6 possible parameters for filtering. One of the filters is a date range with start and ending dates. The date range works fine by itself or when other parameters have values. But if the user enters a value into another control (parameter) and leaves the date range blank the query finds 0 records. Here is my experience with the criteria I have tried.

    1. Between [Forms]![Send Letter]![StartDate] And [Forms]![Send Letter]![EndingDate] THIS WORKS

    2. Like "*" & [Forms]![Send Letter]![StartDate] & "*"- JUST ENTERING THE START DATE AS AN "EQUALS THE DATE" and THAT WORKS

    3. Between Like "*" & [Forms]![Send Letter]![StartDate] & "*" And Like "*" & [Forms]![Send Letter]![EndingDate] & "*"
    BUT THAT TELLS ME I MAY BE MISSING A COMMA when I try to save the query.

    Any thoughts. I can't do VBA and I believe some variation of this should work.

    Jeff

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Supply an alternate value when control is Null.

    Between Nz([Forms]![Send Letter]![StartDate], #1/1/1900#) And Nz([Forms]![Send Letter]![EndingDate], #12/31/2199#)

    Why can't you do VBA? http://allenbrowne.com/ser-62.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    May 2019
    Posts
    65

    Alternative value

    Quote Originally Posted by June7 View Post
    Supply an alternate value when control is Null.

    Between Nz([Forms]![Send Letter]![StartDate], #1/1/1900#) And Nz([Forms]![Send Letter]![EndingDate], #12/31/2199#)

    Why can't you do VBA? http://allenbrowne.com/ser-62.html
    ’’

    First, thanks for the response.
    Second, what is Nz
    Thirds, I don’t have time to learn VBA. But thanks for asking.

  4. #4
    Join Date
    May 2019
    Posts
    65
    I entered everything you said in the criteria field and on saving I get a message that “The expression you entered has an invalid date value”. I reasearched this on line and it appears to be the right syntax.

    ????

  5. #5
    Join Date
    May 2019
    Posts
    65
    Ok, I got past the “invalid date” part and it saves. I just had a couple of characters wrong. However, I’m still getting No Records.

  6. #6
    Join Date
    May 2019
    Posts
    65
    I'm not sure what happened but I wrote the "code" one more time and everything worked. This has been solved per your earlier reply on using Nz.
    Thanks again
    Jeff

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

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2018, 04:06 PM
  2. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  3. Replies: 10
    Last Post: 05-14-2015, 02:06 PM
  4. Replies: 2
    Last Post: 03-14-2014, 05:42 PM
  5. Tab in page control is blank
    By WithoutPause in forum Forms
    Replies: 0
    Last Post: 02-06-2014, 10:40 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