Results 1 to 9 of 9
  1. #1
    Kevo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    Kodiak, Alaska
    Posts
    86

    Query with Between Dates and If Null - All Records

    I have a query that takes End Date and Start Date from a form and returns records between them.....that works fine



    I have looked all over and cant find out how to either prompt for user to have to enter dates....or....better yet, return all records if no dates selected.....

    Any ideas?

    Thank You

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try this as parameter:

    BETWEEN Nz(Forms!formname!StartDate,#1/1/1900#) AND Nz(Forms!formname!EndDate,#12/31/2900#)
    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
    Kevo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    Kodiak, Alaska
    Posts
    86
    Quote Originally Posted by June7 View Post
    Try this as parameter:

    BETWEEN Nz(Forms!formname!StartDate,#1/1/1900#) AND Nz(Forms!formname!EndDate,#12/31/2900#)
    Tried but doesn't seem to work....

    Here is the sql view of my query:

    SELECT tblLoad.LoadID, tblLoad.LoadDate, tblLoad.AutoclaveID, tblLoad.BI, tblLoad.[Process Challenge Device], tblLoad.[Cycle Complete], tblLoad.[Cycle Aborted]
    FROM tblLoad
    WHERE (((tblLoad.LoadDate) Between Nz([Forms]![frmSearchMenu]![qLoadDate1],#1/1/1900#) And Nz([Forms]![frmSearchMenu]![qLoadDate2],#12/31/2900#)));


    Any other ideas? I wouldn't mind if msgbox popped up if user doesnt enter date and prompt to do so....tried that but not sure how...

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Tried but doesn't seem to work....

    What does this mean? Do you get any results?
    Are your date fields formatted as dates in your table?

  5. #5
    Kevo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    Kodiak, Alaska
    Posts
    86
    Quote Originally Posted by alansidman View Post
    What does this mean? Do you get any results?
    Are your date fields formatted as dates in your table?[/COLOR]
    I was answering June7 regarding his suggestion....

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Same questions. What happens - error message, wrong results, nothing? Is the field date type?

    This criteria has worked.
    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.

  7. #7
    Kevo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    Kodiak, Alaska
    Posts
    86
    Quote Originally Posted by June7 View Post
    Same questions. What happens - error message, wrong results, nothing? Is the field date type?

    This criteria has worked.
    I tried:
    WHERE (((tblLoad.LoadDate) Between [Forms]![frmSearchMenu].[qLoadDate1] And [Forms]![frmSearchMenu].[qLoadDate2]));

    and I get this error (if I dont enter a start and end date):

    This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables.

    If I enter a start and end date, it works as desired.

    I want it to enter Between the dates if entered or ALL records if no date is entered. Is this possible? If not, how do I prompt the user to enter the dates?

    And Yes, the fields are dates.
    Last edited by Kevo; 06-13-2012 at 04:45 PM. Reason: add more info

  8. #8
    Kevo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Location
    Kodiak, Alaska
    Posts
    86
    Well, I gave up on getting it to return all records if Between Dates was not entered......so I put this in the on click event for the "search" button that runs the query:
    If Me.qLoadDate1.Value = "" Then
    MsgBox "Please enter start date", vbOKOnly
    Me.qLoadDate1.SetFocus
    Else
    If Me.qLoadDate2.Value = "" Then
    MsgBox "Please enter End Date", vbOKOnly
    Me.qLoadDate2.SetFocus
    Else

    Dim stDocName As String
    stDocName = "rptLoadSearch"

    DoCmd.OpenReport stDocName, acViewPreview
    End If
    End If

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Too bad. I just tested that criteria again and it worked.

    Is null value allowed in that field? That can be an issue with parameterized queries but can be dealt with.
    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.

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

Similar Threads

  1. Replies: 7
    Last Post: 05-23-2012, 02:19 PM
  2. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  3. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  4. Replies: 2
    Last Post: 08-01-2011, 09:30 AM
  5. Not showing records with null sum
    By eww in forum Queries
    Replies: 3
    Last Post: 04-04-2011, 03:10 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