Solved

Setting filter on sub report

Posted on 2000-04-09
9
1,931 Views
Last Modified: 2008-03-04
How do I set a filter on a subreport dynamically at run time? I have a master report with several subreports and in the master report On_Open event proc, I set the subReport source object like this me.child0.SourceObject="MySubReport2". No problem so far. But I also want to set the filter property for the sub report and can't figure out how. Any suggestions? Thanks in advance.
0
Comment
Question by:rion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 2698380
Hello Rion,

Does
MySubreport2.Report.Filter = ...
works the way you want?

PS. English is not my native, sorry if I misunderstood something.
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2698461
Sub objects fill in their details prior to main objects, so if the sub report is based on something in the main report you might have to put the code into the sub's On Open event instead.

A second issue is as Crin says.  When you are referin gto the actual contents of a sub form or a sub report, you specify that with the .Report or .Form properties.

Let's look at a form, (less typing to describe...  :o]  )

If you wanted to Hide the subform named sbFrm, you would use Me!sbFrm.visible - False.  But of course that doesn't address the contents of the subform object;  it only addresses the control that hols the sub form. If you wanted to hide 'cmdBtn' which wass on the sub form, Me.cmdBtn.Visible = False would not work, because that would be addressing an object on the main form.  So how you would address the objects on the sub form need to somehow be distinguished form how you address objects on the main form.  That is done through the .Form property of the sub form control:  Me!sbFrm.Form!cmdBtn.Visible = False.

The same syntax is used for reports, sub reports, and the objects on- and properties of sub reports, hence the '.Report' in Chic's answer.

Brian
0
 

Author Comment

by:rion
ID: 2698666
Here is the on_Open proc for the sub report:
Private Sub Report_Open(Cancel As Integer)

Dim strFilt As String

    If Not IsNull([Forms]![OutputPik]![OutputSub].[Form]![SaveHomFilt]) Then
       strFilt = [Forms]![OutputPik]![OutputSub].[Form]![SaveHomFilt]
       DoCmd.ApplyFilter , strFilt
    End If

End Sub

This works when the report is opened directly but not when it is a sub report.  Can you give me specifics on where issue commands to set the sub report properties? Should this be done in the form that opens the main report before the main report is opened, or in the On_open proc of the main report, or in the on_format proc of the main report detail section or where?
I've tried lots of different approaches but can't seem to get access to apply the filter when the report is opened as a sub report.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:BrianWren
ID: 2699114
Put this in the Open event of the main report, the one that holds the subreport, (This presumes that the name of the SubReport control is 'SubReport'):


      If Not IsNull(Forms!OutputPik!OutputSub.Form!SaveHomFilt) Then
            strFilt = Forms!OutputPik!OutputSub.Form!SaveHomFilt
            Me!SubReport.Report.Filter  = strFilt
            Me!SubReport.Report.FilterOn = True
      End If

Brian
0
 

Author Comment

by:rion
ID: 2700754
Adjusted points from 200 to 300
0
 

Author Comment

by:rion
ID: 2700755
Tried that before, and again. The filter is not applied/active. Here is the Main Report On_Open proc:
Private Sub Report_Open(Cancel As Integer)

Dim strFilt As String
Dim strName As String

strFilt = [Forms]![OutputPik]![OutputSub].[Form]![SaveHomFilt]
strName = "cliHome Search Report"

If Not IsEmpty(varRptNames) Then
    For i = 0 To UBound(varRptNames)
        Me("child" & i).SourceObject = "report.cli" & varRptNames(i)
        If varRptNames(i) = strName Then
            Me("child" & i).Report.Filter = strFilt
            Me("child" & i).Report.FilterOn = True
        End If
    Next
End If

End Sub

You see that the sub report's (child0, child1, ... child6) SourceObject is determined here without problem, so I think the basic approach is correct. But for one report ("cliHome Search Report") I have to specify the filter. When this runs as above, the report is created without filtering. It seems that there is some subtlety here that we're missing. Any ideas on what?
Or is there another way to approach this? Could the sub report's filter be set before the main report opens it? Or any other suggestions? Thanks.
0
 

Author Comment

by:rion
ID: 2700941
The previous comment that listed the Report_Open proc had a logic error:

strName = "cliHome Search Report" should be
strName = "Home Search Report".

The conditional statements
Me("child" & i).Report.Filter = strFilt
Me("child" & i).Report.FilterOn = True
were never executed with the invalid value in strName.

When corrected, the proc generates this run time error: '2455' ("You entered an expression that has an invalid reference to the property Form/Report. The property may not exist or may not apply to the object you specified").

I've also tried the assignment using this syntax :
Me!child0.Report.Filter = strFilt
with the same error resulting.
Any ideas? Thanks.
0
 
LVL 9

Accepted Solution

by:
BrianWren earned 300 total points
ID: 2701983
Apparently the sub report does not yet exist in the Open event.

Try moving the code to the

  Detail_Format()

event.

I just tried addressing the properties that you are using, and got the same error message as you did when I tried to read them, but when I moved the code I _could_ read them.
0
 

Author Comment

by:rion
ID: 2709236
Alright, Thanks for that info.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question