I have a form that has an option group (fraReports) which holds a list of reports to print. This part works fine. I select a report name and click print and that report opens.
Now I want to add a text box to enter a service date that will open the selected report using the text box value (service date) to filter the report to only those dates. I have the field [Service_Date] using the format "mmmm-yyyy" on all my forms and reports so it will show May-2009.
Here is the code I am using:
Now I want to add a text box to enter a service date that will open the selected report using the text box value (service date) to filter the report to only those dates. I have the field [Service_Date] using the format "mmmm-yyyy" on all my forms and reports so it will show May-2009.
Here is the code I am using:
Code:
Private Sub cmdPrint_Click()
Dim stWhere As String
Dim stDescrip As String
Dim stDoc As String
Dim stDateField As String
Const stDateFormat = "mmmm-yyyy"
stDoc = "Court Placement"
stWhere = "[Service_Date]= " & "'" & Me![txtServiceDate] & "'"
If CurrentProject.AllReports(stDoc).IsLoaded Then
DoCmd.Close acReport, stDoc
End If
Select Case [fraReports]
Case Is = 1
If IsDate(Me.txtServiceDate) Then
DoCmd.OpenReport "Court Placement", acViewPreview, stWhere
Else
MsgBox "You must enter a valid service date to print this report.", vbInformation, "No Service Date Entered!"
End If
Case Is = 2
If IsDate(Me.txtServiceDate) Then
DoCmd.OpenReport "Not IV-E Eligible", acViewPreview, stWhere
Else
MsgBox "You must enter a valid service date to print this report.", vbInformation, "No Service Date Entered!"
End If
Case Is = 3
If IsDate(Me.txtServiceDate) Then
DoCmd.OpenReport "Special Adoption Consideration", acViewPreview, stWhere
Else
MsgBox "You must enter a valid service date to print this report.", vbInformation, "No Service Date Entered!"
End If
Case Is = 4
If IsDate(Me.txtServiceDate) Then
DoCmd.OpenReport "Traditional Foster Care", acViewPreview, stWhere
Else
MsgBox "You must enter a valid service date to print this report.", vbInformation, "No Service Date Entered!"
End If
Case Is = 5
If IsDate(Me.txtServiceDate) Then
DoCmd.OpenReport "Treatment Homes", acViewPreview, stWhere
Else
MsgBox "You must enter a valid service date to print this report.", vbInformation, "No Service Date Entered!"
End If
Case Else
MsgBox "There is no report selected to print.", vbExclamation, "No Report Selected!"
End Select
End Sub
Comment