Solved

Setting filter on sub report

Posted on 2000-04-09
9
1,681 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now