I have a form to filter a report. I was wondering if its possible to allow the user to select which report they want to filter by having a dropdown field in the form whcih includes the three reports. All three reports are identical except the second and third have 1 & 2 more fields included, respectively. The report names are rptComplaints, rptComplaintsFollowUp, rptComplaintsDate
Below is a my code in the form to filter. Any recommendations?
Code:
Private Sub btnOpenReport_Click()On Error GoTo Err_Handler
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Dim strFilter As String
Set frm = Forms!frmSearchTool
strFilter = ""
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "rptComplaints"
strDateField = "[SubmissionDate]"
lngView = acViewReport
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
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
'If Len("" & frm!ComboLocation) = 0 Then
' Me.Filter = ""
' Me.FilterOn = False
' Exit Sub
'End If
'Location
'If Len("" & frm!ComboLocation) > 0 Then
If Not IsNull(frm!ComboLocation) Then
'strFilter = "[Location] = '" & frm!ComboLocation & "'"
If strWhere <> "" Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "[Location] ='" & frm!ComboLocation & "'"
End If
'Add filter
'Me.Filter = strFilter
'Me.FilterOn = True
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport
End If
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