Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter a report from a form button with no query

Form Basics

Filter a report from a form button with no query

by  guitardave78  Posted    (Edited  )
This is taken from MSDN and is just the code that i have used and a link to the MSDN article.
This is useful if the form data may be filtered on many different fields, reducing the need for lots of if statements and different queries!!


Code:
[color green]'**in general declarations add**[/color]
Code:
Dim iFilterType As Integer
[color green]'**On Click**[/color]
Code:
Private Sub Button_Click()
Dim fil As Form
Dim stDocName As String
stDocName = "Student_Course"
[color green]'**The report you wish to preview**[/color]
Code:
Set fil = Forms![StudentID1]
[color green]'**The form you have added the button to**[/color]

Code:
If iFilterType = acApplyFilter Then
    DoCmd.OpenReport stDocName, acPreview, , fil.Filter
[color green]'**If a filter has been set on the form then apply it to the report** [/color]
Code:
Else
    DoCmd.OpenReport stDocName, acPreview
[color green]'**If there is no filter then just generate the normal report**[/color]
Code:
End If
    
End Sub

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
iFilterType = ApplyType
End Sub

The Link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnimo00/html/o2k00a4.asp
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top