Hi,
I have a form with 2 areas on it. One that shows an option group allowing users to select the report the wish to run, the other part shows date fields which the user can select and run the report showing that date range. I currently have 2 buttons which are working to do one thing at a time, one runs reports based on the option choosen, and one runs a report based on dates selected. That part works well. What I am trying to do is have one button to do both. Allow users to select the report on the option buttons, and then select the dates that report should run. I am not sure how to combine the code to have this work. I have put the 2 samples of code I am currently using.
Code:
Private Sub cmdRunDates_Click()
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strReport = "rptCountySummary"
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
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
'Close the report if already open: otherwise it won't filter properly.
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
and
Code:
'Private Sub cmdThisMonth_Click()
'If optionRpt = 1 Then
' DoCmd.OpenReport "rptCountySummary", acViewReport
'ElseIf optionRpt = 2 Then
' DoCmd.OpenReport "rptCountyMainRU", acViewReport
'ElseIf optionRpt = 3 Then
' DoCmd.OpenReport "rptCountyInvoice", acViewReport
End If
End Sub
I tried several ways to incorpate this code, but have been unsuccessful so far. I have already wasted 3 days spinning my wheels on this.
I thank anyone in advance who is brave enough to take this one on