Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting filter on sub report

Posted on 2000-04-09
9
Medium Priority
?
2,269 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
  • 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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 1200 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

Technology Partners: 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!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

783 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