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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.