Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting filter on sub report

Posted on 2000-04-09
9
Medium Priority
?
2,156 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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