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

    Run report based on Option and Combo Boxs

    Hi,

    I have some code that worked well for a user to select the report from a combo box and then date combo box's. I am now trying to do the same thing for them selecting the report type by the option group but then selecting the client (episodeID) from a cmbEpisodeID combo box. I actually have 2 combo box's, one is selecting the staff ID (CmbStaffID). I would like the report choosen in the Option group to run filtering either StaffID or EpisodeID depending if either or both are choosen. I tried playing with the code to have it filter on the Combo box containing Episode ID to start with yet can't get it to work. Currently the correct report is showing up, yet no data.

    Code:
    Option Compare Database
    Option Explicit
    Private Function GetReport() As String
    If optManagersProgress = 1 Then
    GetReport = "rptProgressNotes"
    ElseIf optManagersProgress = 2 Then
    GetReport = "rptStaffSummaryProCode"
    ElseIf optManagersProgress = 3 Then
    GetReport = "rptStaffSummaryLocation"
    End If
    End Function
    Private Sub cmdSeeProgressNotes_Click()
         Me.Visible = False
        Dim strReport As String
        Dim strEpisodeField As String
        Dim strWhere As String
        Dim lngView As Long
        strReport = GetReport()
        strEpisodeField = "[EpisodeID]"
        lngView = acViewPreview
        'Build the filter string.
        If (Me.CmbEpisodeID) Then
            strWhere = "strEpisodeField" = Me.CmbEpisodeID
        'Close the report if already open: otherwise it won't filter properly.
        End If
        If CurrentProject.AllReports(strReport).IsLoaded Then
            DoCmd.Close acReport, strReport
        End If
        'Open the report.
        DoCmd.OpenReport strReport, lngView, , strWhere
    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 Sub


  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,521
    Try

    strWhere = "strEpisodeField = " & Me.CmbEpisodeID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    I think it tried to work, yet a box popped up asking for me to enter StrEpisodeField. I was unsure what to put here, in the code that was used for Dates this actually said strDateField = "[ServiceDate]".

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It needs to be the name of the field in the report's record source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Report based on combo box values as columns
    By sadozai in forum Reports
    Replies: 2
    Last Post: 12-09-2011, 04:40 PM
  2. Replies: 9
    Last Post: 08-30-2011, 04:08 PM
  3. Combo Boxs
    By clean32 in forum Forms
    Replies: 2
    Last Post: 06-14-2011, 08:48 AM
  4. sub forms & combo boxs
    By clean32 in forum Forms
    Replies: 38
    Last Post: 06-13-2011, 06:59 PM
  5. Working with Two Combo boxs
    By Della Smith in forum Database Design
    Replies: 2
    Last Post: 08-01-2008, 02:52 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