Printing filtered reports

pesto

Registered User.
Local time
Today, 12:31
Joined
Mar 8, 2005
Messages
11
I have an odd problem. I have a small for make up so that you can select how to filter a report. There are two combo boxes where you can select a range of dates, and any records within that range will be displayed on the report.

There are two buttons on the form. One to preview the report and one to print the report. The preview button works perfectly. The print button almost works, but somehow does not apply the filter correctly. The code for the two buttons is nearly identical.

Here's what's strange. When I step through the code for the print button it works PERFECTLY. When I go back and run the code, the filter is not applied. What in the world is going on? Is there some way I can refresh the report before I print it? Here's the code


Private Sub Command6_Click()

Dim fromDate As Date
Dim toDate As Date

DoCmd.OpenReport "Graduating Students", acViewPreview

' get dates from form
' ensure dates used are not Null
If (Combo1) Then
fromDate = Combo1
Else
fromDate = #1/1/2000#
End If

If (Combo3) Then
toDate = Combo3
Else
toDate = #1/1/2100#
End If

' apply filter: fromDate <= [Graduation Date] <= toDate
Reports![Graduating Students].Filter = _
"((([Enrollment Information].[Graduation Date] >= #" & fromDate & "#) " & _
"And ([Enrollment Information].[Graduation Date] <= #" & toDate & "#)))"
' display filter information on report
Reports![Graduating Students]![Text35] = fromDate
Reports![Graduating Students]![Text38] = toDate
Reports![Graduating Students].FilterOn = True

DoCmd.PrintOut
DoCmd.Close acReport, "Graduating Students"
DoCmd.Close acForm, "Get Graduating Students"

End Sub


I appologize for the clumsy table names and such. I am fairly new at databases.
 
Last edited:
Update. When I print, Access is using the filter in the filter property of the form, not the filter I am trying to apply using VBA.
 

Users who are viewing this thread

Back
Top Bottom