Results 1 to 7 of 7
  1. #1
    Reaper is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    57

    Between And operator gives inconsistent result

    I have a report that is filtered by date using a form with unbound text boxes. The user enters the beginning and ending dates and the report criteria looks at the text boxes for the values of the Between/And operator.



    The problem that I am having is that when I enter 1/1/2013 and 1/31/2013 for the dates, any record with a date of 1/31/2013 is not included in the report. However, if I put in 2/1/2013 I get the 1/31/2013 records AND the 2/1/2013 records.

    Has anybody seen this or have a solution?

    Here is my code:
    Private Sub cmdSubmit_Click()

    On Error GoTo Err_Handler

    If IsNull(Me!dtStartDate.Value) Then
    Me!dtStartDate.Value = "1/1/2000"
    End If

    If IsNull(Me!dtEndDate.Value) Then
    Me!dtEndDate.Value = Date + 1
    ElseIf Me!dtEndDate.Value = Date Then
    Me!dtEndDate.Value = Date + 1
    End If

    DoCmd.OpenReport "rptreceivinglog", acViewPreview
    Exit Sub

    Err_Handler:
    MsgBox Err.Description, , "Submit Fail"
    Exit Sub

    End Sub

    Code for the BETWEEN/AND operator used in the Report SQL:

    Between [Forms]![frmReceivingLogReportDates]![dtStartDate] And [Forms]![frmReceivingLogReportDates]![dtEndDate]

  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,641
    My guess would be that your values include a time. That would cause what you're seeing. You can get around it with DateValue().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    qa12dx is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    india
    Posts
    112
    also, exit the dt textbox. do a goto control (any other than the dt fields) before the qry triggers

  4. #4
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    Code for the BETWEEN/AND operator used in the Report SQL:

    Between [Forms]![frmReceivingLogReportDates]![dtStartDate] And [Forms]![frmReceivingLogReportDates]![dtEndDate][/QUOTE]

    I use this sometimes..


    Between [Forms]![frmReceivingLogReportDates]![dtStartDate] And Cdate([Forms]![frmReceivingLogReportDates]![dtEndDate] & " 11:59:59 PM")

    you add the time componet to the end date unless someone will be adding a record at the last second in the day this will work as well.

    hope this helps

  5. #5
    Reaper is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    57
    Thanks for the help.
    The fix ended up being the CDATE function that alcapps suggested.
    Using DATEVALUE() produced the same result. I had already set the format to short date for all the fields.
    I guess the time portion is still in play even if all the table and form fields are set to short date.

  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,641
    Glad you have a solution. I suspect DateValue() would also have worked. I should have specified that it would be used on the field value. In SQL view:

    WHERE DateValue(FieldName) Between ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I wonder if the reason that CDate() works while DateValue() doesn't is because the OP sometimes is a assigning a String to the dtStartDate Field

    Me!dtStartDate.Value = "1/1/2000"

    instead of assigning a Date

    Me!dtStartDate.Value = #1/1/2000#

    to the Field? CDate would convert it to a Date, of course, but DateValue wouldn't.

    Linq ;0)>

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

Similar Threads

  1. Replies: 3
    Last Post: 09-12-2012, 11:48 AM
  2. Inconsistent Code Execution
    By Paul H in forum Forms
    Replies: 2
    Last Post: 09-19-2011, 10:06 AM
  3. Inconsistent??
    By bginhb in forum Programming
    Replies: 3
    Last Post: 09-07-2011, 03:10 PM
  4. Save Changes - inconsistent updates
    By 161 in forum Queries
    Replies: 1
    Last Post: 03-19-2011, 03:16 AM
  5. Inconsistent Query Error...
    By DHavokD in forum Queries
    Replies: 8
    Last Post: 06-11-2009, 09:58 AM

Tags for this Thread

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