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: '**in general declarations add** Dim iFilterType As Integer
'**On Click** Private Sub Button_Click() Dim fil As Form Dim stDocName As String stDocName = "Student_Course" '**The report you wish to preview** Set fil = Forms![StudentID1]'**The form you have added the button to**
If iFilterType = acApplyFilter Then DoCmd.OpenReport stDocName, acPreview, , fil.Filter '**If a filter has been set on the form then apply it to the report**
Else DoCmd.OpenReport stDocName, acPreview '**If there is no filter then just generate the normal report** End If
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer) iFilterType = ApplyType End Sub