Using a form to Filter data for a report

  • Thread starter Thread starter Chip
  • Start date Start date
C

Chip

Hello, I am relatively now to ACCESS so please be gentle with the VB...

I am wanting to have a Form that has 2 combo boxes that I want the user to
select a record for each one then the person hit a Print button and the
Report be filters by the 2 selections from the form.

Basically what I have is a single table that has information about students
in college and I want to build an easy user interface so that if they want a
list of the Seniors that are Majoring in Pre-med. Then the user will select
Senior from the "Class" Combo box and then select Pre-Med from the "Major"
Combo box. then the report that is printed will only show the Students that
are a Senior and Majoring in Pre-Med.

There may be a better way if there please let me know. AS ALWAYS, THANKS IN
ADVANCE!!!!
-Chip-
 
I generally don't place any criteria in the report's record source. I use a
where clause when opening the report. Just create the code to preview the
report using the command button wizard. Then go in and modify the code to
add a WHERE clause in DoCmd.OpenReport:
'code that opens report
Dim strWhere
strWhere = "1=1 "
If Not IsNull(Me.cboClass) Then
strWhere = strWhere & " AND [Class] = """ & Me.cboClass & """"
End If
If Not IsNull(Me.cboMajor) Then
strWhere = strWhere & " AND [Major] = """ & Me.cboMajor & """"
End If
DoCmd.OpenReport "rptName", acPreview, , strWhere
 
Back
Top