Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2003
    Location
    Perth, Western Australia, Australia
    Posts
    150
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filtering an Access Report (2000)

    Hi all,
    In the attached file(PetrolCars.mdb), there is the report
    Attached Files Attached Files

  2. #2
    2 Star Lounger
    Join Date
    May 2003
    Location
    Perth, Western Australia, Australia
    Posts
    150
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filtering an Access Report (2000)

    Thankyou so much Hans, your explanation and db was clear-cut and has helped me get a headstart on this access report phenomenon.
    Greatly appreciated <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filtering an Access Report (2000)

    The "elegant" way is to create a form on which the user can specify the date range, and open the report from that form. Let's say that you have text boxes txtStartDate and txtEndDate. Code to open the report for dates between txtStartDate and txtEndDate could look like this:

    Private Function DoReport(fPreview As Boolean)
    Const conActionCanceled = 2501
    Const conReportName = "rptPetrol/DriveCars"
    Dim strFilter As String
    On Error GoTo Handle_Err

    ' Check whether dates are valid.
    If IsNull(Me.txtStartDate) Then
    MsgBox "Enter a Start Date.", vbExclamation
    Me.txtStartDate.SetFocus
    Exit Function
    ElseIf IsNull(Me.txtEndDate) Then
    MsgBox "Enter an End Date.", vbExclamation
    Me.txtEndDate.SetFocus
    Exit Function
    ElseIf Me.txtEndDate < Me.txtStartDate Then
    MsgBox "End Date may not be before Start Date.", vbExclamation
    Me.txtEndDate.SetFocus
    Exit Function
    End If

    strFilter = "[Date/Time] Between #" & Format(Me.txtStartDate, "mm/dd/yyyy") & _
    "# And #" & Format(Me.txtEndDate, "mm/dd/yyyy") & "#"

    If fPreview Then
    DoCmd.OpenReport conReportName, acViewPreview, , strFilter
    Else
    DoCmd.OpenReport conReportName, acViewNormal, strFilter
    End If

    Exit Function

    Handle_Err:
    If Err <> conActionCanceled Then
    MsgBox Err.Description, vbExclamation
    End If
    End Function

    Call this function with True as argument to see it in preview mode, or False to send it to the printer without viewing it.

    I have attached the database with such a form. It also demonstrates how to refer to the selected date range in the report header. (I removed the other forms to keep size down!)
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •