Access 2003 - Trying to Filter a report based on a combo box

allegro

New member
Local time
Today, 06:54
Joined
Feb 4, 2015
Messages
3
Hi there

I hope that someone with greater understanding of these matters can help me out.

Here's a little problem that I can't solve...:banghead:

My Access 2003 Database contains the following objects:

1. tblTrackerData
- this contains over 1,000 student enrollment records.
One of the fields "QualCourseName" (text) contains the name of the Training Course that the student has enrolled in.

2. qryCourseNamesGrouped is a query based upon the above table with one field only - QualCourseName. This includes the names of the training courses and has been grouped so that only 17 training courses appear, not over 1,000.

3. frmParameter is a form that includes a combo box cboFiltered based on the above query AND a command button CmdFiltered to open a report rptCourseNamesGrouped and filter the report based on the selection made from the combo box.

I have added the following code to the OnClick event attached to the cmd button"
========================================================

Private Sub cboFiltered_Click()
On Error GoTo Err_cboFiltered_Click

Dim stDocName As String

stDocName = "rptCourseNamesGrouped"
DoCmd.OpenReport stDocName, acPreview

Exit_cboFiltered_Click:
Exit Sub

Err_cboFiltered_Click:
MsgBox Err.Description
Resume Exit_cboFiltered_Click

Dim frm As Form
On Error GoTo cmdPrintErr
Set frm = Forms!frmFiltered
If frm.FilterOn Then
DoCmd.OpenReport "rptCourseNamesGrouped", acViewPreview, , frm.Filter
Else
DoCmd.OpenReport "rptBasicDetails", acViewPreview
End If
cmdPrint_Exit:
Exit Sub
cmdPrintErr:
MsgBox " err" & Err.Description
Resume cmdPrint_Exit

End Sub
====================================================

When I click on the cmd button, the entire report is opened, instead of the selection that I made in the dropdown list.

Any suggestions would be GREATLY appreciated.

Regards
 
You exit the sub before you come to the filtering part, (but you can't open a report again when it is open, then you've to close it first)!!
Code:
Private Sub cboFiltered_Click()
On Error GoTo Err_cboFiltered_Click

    Dim stDocName As String

    stDocName = "rptCourseNamesGrouped"
    DoCmd.OpenReport stDocName, acPreview

Exit_cboFiltered_Click:
    [B][COLOR=Red]Exit Sub[/COLOR][/B]
 
Thanks JHB

I will try this when I'm not working this weekend.

Regards
 

Users who are viewing this thread

Back
Top Bottom