Results 1 to 2 of 2
  1. #1
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56

    Filter report on Selcted Details

    Hi,



    I have this code that works well on another form I am using, and I am trying to edit it to work on a new form to do a similar task. I want a user to select the cmdSelectEpisode from the first selection box, then I want them to enter dates that they want to run the report in the txtstartdate and txtenddate unbound fields. When the click on the cmdEditEpisode button I am trying to make a report appear that only shows records that match the first criteria selected and to run between the 2 dates selected, but at the moment I cant get it to filter on the dates as well, only the first selected criteria. I am unsure how to get 3 criteria to work together.

    Code:
    Private Sub cmdEditEpisode_Click()If IsNull(Me.cmdSelectEpisode) Then
     MsgBox "You must select an episode that you want to edit first", vbOKOnly, "Must Select Client"
     Else
          Me.Visible = False
        Dim strReport As String
        Dim strDateField As String
        Dim strWhere As String
        Dim lngView As Long
        Const strcJetDate = "\#mm\/dd\/yyyy\#"
        strDateField = "[ServiceDate]"
        lngView = acViewPreview
        'Build the filter string.
        If IsDate(Me.txtStartDate) Then
            strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
        End If
        If IsDate(Me.txtEndDate) Then
            If strWhere <> vbNullString Then
                strWhere = strWhere & " AND "
            End If
          End If
        'Open the report.
         DoCmd.OpenReport "rptProgressNotes", acViewReport, , "EpisodeID=" & Me.cmdSelectEpisode
    Exit_Handler:
        Exit Sub
    Err_Handler:
        If Err.Number <> 2501 Then
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
        End If
        Resume Exit_Handler
    End If
    End Sub

  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,926
    What is name of the date field in the report RecordSource?

    DoCmd.OpenReport "rptProgressNotes", acViewReport, , "EpisodeID=" & Me.cmdSelectEpisode & " AND datefieldname BETWEEN #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#"

    If you want to make the dates optional then use code to construct string into the strWhere variable and concatentate.

    DoCmd.OpenReport "rptProgressNotes", acViewReport, , "EpisodeID=" & Me.cmdSelectEpisode & strWhere
    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: 1
    Last Post: 08-27-2012, 12:33 PM
  2. Replies: 3
    Last Post: 12-14-2011, 01:24 PM
  3. Missing client details report
    By crxftw in forum Reports
    Replies: 3
    Last Post: 08-16-2011, 12:19 PM
  4. Multiple Details Sections of report
    By nkuebelbeck in forum Reports
    Replies: 1
    Last Post: 03-17-2010, 09:34 AM
  5. Replies: 26
    Last Post: 11-06-2009, 10:16 AM

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