473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Filtering (sorting) subreport from subform

167 100+
Hi!

I have a MainForm and a SubForm on it. They're linked and can be filtered, sorted etc...
I designed MainReport and SubReport that should match filter and sort criteria from MainForm and SubForm.
I have a PrintButton on MainForm that opens the report!

At this moment my MainReport is being filtered and sorted excatly the way the MainForm is, and I was trying to get ma SubReport to be filtered and sorted the way the SubForm is.

I'm reading forums for the last three days trying to find some inspiration and I finaly decided to ask for help.

So please help out guys!
Thanks,

Hrvoje
Oct 17 '07 #1
25 14794
nico5038
3,080 Expert 2GB
Like the main/sub form, the report/subreport can be linked.
Just single-click the subreport and look in the Properties window under the Data tab to see the Linkage "master" and "child" properties where the field(s) need to be specified of the link.

Nic;o)
Oct 17 '07 #2
hjozinovic
167 100+
Like the main/sub form, the report/subreport can be linked.
Just single-click the subreport and look in the Properties window under the Data tab to see the Linkage "master" and "child" properties where the field(s) need to be specified of the link.

Nic;o)


Hi Nic;o!

Thanks for the reply!
My MainReport and SubReport are linked the same way the Form and Subform are.
But when filtering the MainForm using Filtr By Form from the toolbar, I'm also able to filter my Subform in the same blow.
What I want is to pass that filter from the subform to my subreport.

This is how im filtering MainForm:
-------------------------------------------------------------------------------

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Err_Report_Open

Me.Filter = Forms!fObracunPlace.Filter
Me.FilterOn = Forms!fObracunPlace.FilterOn

Me.OrderBy = Forms!fObracunPlace.OrderBy
Me.OrderByOn = Forms!fObracunPlace.OrderByOn

Exit_Report_Open:
Exit Sub

Err_Report_Open:
Resume Exit_Report_Open

End Sub
-------------------------------------------------------------------------

I tried to use the same principle when filtering subreport but I get an Error ...

Did anyone figured out how to filter subreports too????

Thanks in advance for the support!

Hrvoje
Oct 18 '07 #3
nico5038
3,080 Expert 2GB
Hmm, depending on the Access version you could use the report's OpenArg to pass the filter and apply it to the subreport.
Another 100% solution would be to dynamically change the subreport's query.
This requires a "template" copy of the original filter. In the [Print] button you can manage the querydef's SQL property with a replace of the trailing ";" with the subformfilter.

Getting the idea ?

Nic;o)
Oct 18 '07 #4
hjozinovic
167 100+
Hi again Nico!

Thanks for your advice! I must admit that I don't get it, I'm new to coding so the simple solution would be the best...

Can you please give me an example of what should I do?
I know it's like spoonfeeding, but I'm realy confused with this.

FYI.....I'm using Access 2003.

Thanks!
h.
Oct 18 '07 #5
nico5038
3,080 Expert 2GB
Hi h.

I always start with directions so I don't spoil the coding fun for the experienced members :-)

The A2003 should have for forms the OpenArgs property in the parameterlist when issuing a docmd.openreport "rptName", ...
Shold be the last one.
By moving the Me.subformname.form.filter as the Openargs parameter, you can use the OnOpenevent of the mainreport to intercept this value with:
Expand|Select|Wrap|Line Numbers
  1. IF len(nz(Me.Openargs)) > 0 then
  2.    me.subReportName.report.filter = Me.Openargs
  3. endif
  4.  
The other solution would imply code behind the Print button like:
Expand|Select|Wrap|Line Numbers
  1. Dim qd as DAO.Querydef
  2. set qd = currentdb.querydefs("<qry of your subreport>")
  3. qd.SQL = Translate(qd.SQL,";", " WHERE " & Me.subform.form.filter & ";")
  4. Docmd.Openreport ...
  5.  
Getting the idea ?

Nic;o)
Oct 18 '07 #6
hjozinovic
167 100+
Hi N.

I must admit I'm feeling confused now. I tried both of your solutions and I allways get the same error: "2101 - The settings you entered is not valid for this property"

I tried to turn the filter on in my SubReport after copy/pasting the filter from the SubForm. If i turn it on manually by setting FilterOn to "yes", then it filters the way I want it to be filtered.
However, If I try to do it in VB it gives me the above stated error.

I want to set the Filter, FilterOn, OrderBy and OrderByOn properties in VB!!!
Do you have any other suggestions left?

Thx!
Oct 22 '07 #7
nico5038
3,080 Expert 2GB
The second option should always work.
Did you add the code behind the Print button on a form and not in the report ?

Nic;o)
Oct 22 '07 #8
hjozinovic
167 100+
Hi there!

I tried the second solution (with more attention this time:-)....) and it works! yay!
But it works only for filtering, and I can't make it work for sorting too.
Oct 23 '07 #9
nico5038
3,080 Expert 2GB
For that you'll need to add the string " ORDER BY " & Me.Orderby & ";" after the WHERE that's already in place.

Nic;o)
Oct 23 '07 #10
hjozinovic
167 100+
Hi Nico!

thanks alot! I tried that allready. This is my current code:

Expand|Select|Wrap|Line Numbers
  1.     Dim FinalSQL As String
  2.     Dim sqlString As String
  3.     Dim Fltr As String
  4.     Dim Sort As String
  5.  
  6.  
  7.     sqlString = "SELECT qObracun.oID, qObracun.otID, qObracun.otcID, qObracun.oDatum, qObracun.oOpis, qObracun.oPotrBAM, qObracun.oPotrBAMrac, qObracun.oPotrEUR, qObracun.oPotrEURrac, qObracun.oPotrHRK, qObracun.oPotrHRKrac, qObracun.otcBAM, qObracun.otcEUR, qObracun.otcHRK, qObracun.UkupnoBAM, qObracun.UkupnoBAMrac FROM qObracun"
  8.     Fltr = "qObracun.oID Like '*'"
  9.     Sort = "qObracun.oID"
  10.  
  11.  
  12.  
  13.     If Me.FilterOn = True Then
  14.     If Me!sfObracun.Form.Filter <> "" Then Fltr = Me!sfObracun.Form.Filter
  15.     End If
  16.  
  17.  
  18.     If Me!sfObracun.Form.OrderBy <> "" Then Sort = Me!sfObracun.Form.OrderBy
  19.  
  20.  
  21.     FinalSQL = sqlString & " WHERE " & Fltr & " ORDER BY " & Sort & ";"
  22.  
  23.     CurrentDb.QueryDefs("qsrObracun").SQL = FinalSQL
  24.  
  25.  

It filters my subreport perfectly, but sorting is not working.
I tried:
If OrderByOn is True.... similar to filtering..but that doesn't work either...

Do yuo have any suggestions left?

h.
Oct 29 '07 #11
nico5038
3,080 Expert 2GB
Oops, I forgot to realize it's a report you're working with and no form :-(

Reports won't work with the query's OrderBy, but will need the GroupLevel to be set correctly.
Check:
http://allenbrowne.com/ser-33.html

Nic;o)
Oct 29 '07 #12
hjozinovic
167 100+
Hi!

I tried to set the GroupLevel property of my SubReport... In the Field/Expression column I entered the path to SubForm's OrderBy property and it works great. Now my SubReport is being sorted by the same field as the SubForm.
Only now I have SortOrder problem. I tried this code in SubReport's Open event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. If Right(Forms!fObracunTure!sfObracun.Form.OrderBy, 4) = "DESC" Then Me.GroupLevel(0).SortOrder = True
  4.  
  5. End Sub
This doesn't seem to work. But I'm getting closer thanks to your help :-)
Oct 30 '07 #13
nico5038
3,080 Expert 2GB
Add:
Expand|Select|Wrap|Line Numbers
  1. Me.GroupLevel(0).SortOrder = True 'For Desc order, else False
  2.  
Nic;o)
Oct 30 '07 #14
hjozinovic
167 100+
Hi N.!

I tried the line of code you suggested and it did nothing.
I used a MsgBox to check if "DESC" is what I get when sorting Descending and it was correct.
Sorting does work, but only for Ascending sort order which is default in my SubReport. I just can't get it to work in Descending sort order too.

Ideas?
Nov 5 '07 #15
nico5038
3,080 Expert 2GB
Strange, did you check the output to be in DESC order and did you check the datatype (text sorts differently as numbers and dates).

Perhaps you can create a small test database with the table(s) and the report, then add an attachement to a comment here so I can check why it doesn't work.

Another option, when you have only Ascending working, is to add an "inverted" field to get the opposite sort, e.g. change 1 into -1, 2 into -2, etc and the ascending becomes descending.

Nic;o)
Nov 5 '07 #16
hjozinovic
167 100+
hi N.
I creatde a test database but don't know how to attach it to my comment.
How can I do that????
Nov 10 '07 #17
nico5038
3,080 Expert 2GB
1) First create the comment.
2) Save/store it
3) Use the "Edit/Reply" link bottom right under the comment.
4) Add the attachment on the edit form.

Nic;o)
Nov 10 '07 #18
hjozinovic
167 100+
Here is a Test database that reflects my problem, and my current situation.
You will notice that filtering works, and sorting only works for Ascending sort order which is default in my subreport.

Hope you'll be able to come up with something...


p.s. I deleted all the records so it's smaller, so you will need to put in some info to test it.
Attached Files
File Type: zip Test.zip (24.6 KB, 229 views)
Nov 10 '07 #19
nico5038
3,080 Expert 2GB
Hmm, took a quick look at your .mdb, but found for a testcase:
Forms!fMain!sfSub.Form.OrderBy the value:
[qSub].[aDescription] DESC, qSub.aValue DESC

This would require two GroupingLevels and for each the DESC test and the filling of the field in the controlsource.

Personally I would switch from using a report to use the form with a white background and with a "Print form" button with the property "Show when" set to "Only form".

Will save a lot of code....

Nic;o)
Nov 11 '07 #20
hjozinovic
167 100+
I have tried the basic step with qdefs for my test base and....it works!!!!!!!!!
Filtering and sorting works the way I want it. BUT...that is a test base, and I haven't found any difference between my database and my Test base.

Only difference I can remember is that they were designed on different PC's, but both with ACC2003.

I'm attaching the new test base here for some future users that might find it helpful.

Do you have any suggestions on how to make it work now?
I hope I won't be forced to make it from the scratch :-(

h.
Attached Files
File Type: zip Test2.zip (59.2 KB, 214 views)
Nov 13 '07 #21
nico5038
3,080 Expert 2GB
Check the Tools/References under VBA to see or there's no one missing...

Nic;o)
Nov 13 '07 #22
hjozinovic
167 100+
Hi N.

I finaly found the source of my problem. The problem is my Sum field in SubReport's footer. If I don't have the Sum field than SubReport displays the sorted data just fine, but when I add the Sum field it overrides the sorting even though underlying query is sorted.
I tried to use DSum function, but with no success...
I hope I'll get it to work soon.
Nov 19 '07 #23
nico5038
3,080 Expert 2GB
Hmm, you're using both subform and subreport.
Keep in mind that a subreport is sorted according the GroupLevel specified and NOT according the Order By in the query!

Nic;o)
Nov 19 '07 #24
hjozinovic
167 100+
Hi N. and everyone else out there reading this!

I finally FOUND THE SOLUTION to my problems!
What a great feeling :-)
What I did is this:

1. I Used Querydefs as described above to change the SQL definition of the underlying query for my SubReport (This is where I'm handleing SubReport's Filtering and Sorting).
2. I added a RUNNING SUM text box for every value field that needs to be summarised in my SubReport.
This Running sum text box [RSumBox] is placed in the detail section of a SubReport and I have a Sum control in Report footer section of my SubReport with record source set to (=RSumBox).

For anyone interested in understanding this better I attached the Test base to this reply. You can see all the code inside and everything else as explained above...

Once again I must say THANK YOU Nic;o! for being there for me every single day and for giving great ideas and advices. Respect!

h.
Attached Files
File Type: zip Test3-final and it works.zip (27.4 KB, 389 views)
Nov 20 '07 #25
nico5038
3,080 Expert 2GB
Well done :-)

Glad to be of assistance !

Nic;o)
Nov 20 '07 #26

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
1
by: Melissa | last post by:
A form in my database has multiple subforms. If any subform has no data, the borders of the subform still display on screen and also are printed if I print the main form. Reports are different. If...
1
by: Melissa | last post by:
Sorry if this becomes a repeat! I am having trouble with my newsreader and don't know if this got posted yeserday or not or if anyone responded. A form in my database has multiple subforms. If...
2
by: nathanwalsh | last post by:
What are some of the differences between subforms and subreports? Here's my problem: I've got a form that lists a group of technicians. The main form lists basic information (name, job title, etc)...
3
by: lorirobn | last post by:
Hello, I have a report which uses a subreport. When I run the report, I get "Enter Parameter Value" error message for "tblGuestRoom". I click ok and the report seems to work fine. I...
1
by: kkrizl | last post by:
I have a form that displays general information about an alarm permit location. There's a subform that shows detailed information about burglar alarms that have gone off at the location. When a...
9
by: Alan | last post by:
Hmmm, I'm not too good with the syntax of referencing a subreport. I have frmInvoice which has the invoice details (e.g. ProductCode, ProductCost etc) in the subform frmInvoiceDetails. I'm trying...
3
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
3
by: Simon van Beek | last post by:
Dear reader, How to change the RecordSource for a subReport. For forms the syntaxes is:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.