Dates on 2 textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • margot
    New Member
    • Sep 2007
    • 48

    Dates on 2 textboxes

    I am using access 2007 and I am trying to open a report with a range of dates that the user inputs in two textboxes. I am using the code below, however when I run it, it will open the rerport, but with all dates; and I want it to open with the range of dates on the textboxes.
    Thanks in advance
    [Code=vb]
    Private Sub cmdPrintReport_ Click()

    Dim pstCriteria As String

    If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
    pstrCriteria = "[DateReceived]" >= "# " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"

    DoCmd.OpenRepor t "rptDateReceive d", acViewPreview, , pstrCriteria

    Else
    MsgBox "You must enter two dates"

    End If

    End Sub
    [/Code]
    Last edited by Rabbit; Oct 16 '07, 06:44 PM. Reason: Please use code tags.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by margot
    I am using access 2007 and I am trying to open a report with a range of dates that the user inputs in two textboxes. I am using the code below, however when I run it, it will open the rerport, but with all dates; and I want it to open with the range of dates on the textboxes.
    Thanks in advance
    [Code=vb]
    Private Sub cmdPrintReport_ Click()

    Dim pstCriteria As String

    If IsDate([txtFirstDate]) And IsDate([txtEndDate]) Then
    pstrCriteria = "[DateReceived]" >= "# " & [txtFirstDate] & "# and [DateReceived]<=#" & [txtEndDate] & "#"

    DoCmd.OpenRepor t "rptDateReceive d", acViewPreview, , pstrCriteria

    Else
    MsgBox "You must enter two dates"

    End If

    End Sub
    [/Code]
    This:
    Code:
    "[DateReceived]" >= "# "
    Should be this:
    Code:
    "[DateReceived] >= # "
    Also, in the future you can use DateField BETWEEN #Date1# AND #Date2#.

    Comment

    • margot
      New Member
      • Sep 2007
      • 48

      #3
      Originally posted by Rabbit
      This:
      Code:
      "[DateReceived]" >= "# "
      Should be this:
      Code:
      "[DateReceived] >= # "
      Also, in the future you can use DateField BETWEEN #Date1# AND #Date2#.
      Thank you Sir. It works great.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Not a problem, good luck.

        Comment

        Working...