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