473,468 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Filtering subforms in reports

37 New Member
I have two databases, one with products and another with accessories and a query which relates products and accessories. I created a simple report which lists the product fields and has two subforms. The first subform simply lists all the accessories. The second subform needs to list a subset of accessories so I wrote a few lines in VBA which is called on the LOAD control. The VBA simply gets some criteria from another table, makes some decisions and sets a filter to limit accessories by a date:

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "([OldNew] > " & Format(Min_yr, strcJetDate) & ") AND ([Nacido] <= " & Format(Max_yr, strcJetDate) & ")"
  2. Me.FilterOn = True
  3.  
The problem is that the subform works fine when you load it from the interface. However, in the report the filter never gets applied and the form simply displays the same as the first subform, ie all the accessories are shown. The subform when displayed as part of a report does not call the VBA code. How can I get around this?

Many thanks!
Mar 17 '11 #1
6 2285
garfieldsevilla
37 New Member
I guess the only way to do this is create two queries, one with all the accessories for a product and another which accessories for a product filtered by date.

Does anyone know of a more elegant solution?
Mar 20 '11 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Let's get the terminology right to start with, to save you getting any more confused (Because there should be no doubt that misuse of terminology can cause confusion). The Load event would fire your code in the event procedure if there were a load event for subforms.

Subforms are not loaded as such. The report is loaded. The subforms are included as part of the design of the report. Does that explain why it's not running the code?

You need to consider positioning your code somewhere within the Load event of the report I would suggest. Particularly I suspect, because it is relative to the report itself rather than the subform (even though it may deal directly with objects on the subform).
Mar 20 '11 #3
garfieldsevilla
37 New Member
thanks- yes, that is certainly what I have observed.

Looking at using a function in the query linked to the subform as a way of controlling output.
Mar 21 '11 #4
NeoPa
32,556 Recognized Expert Moderator MVP
GarfieldSevilla:
thanks- yes, that is certainly what I have observed.
I take this as a response to my paragraph #2. Fine.
GarfieldSevilla:
Looking at using a function in the query linked to the subform as a way of controlling output.
Is this a question? Maybe a request for more help?

I'm not particularly inclined to spend more effort on a new question when you don't seem to have responded in any way to my previous suggestion in para #3. Not only is it a waste of time if you ignore what I post, but I also have no reason to suppose you understand the thrust of what I'm saying. The question(?) doesn't seem related in any way I can see to what I was suggesting. Maybe you just want to be in control of where we go with this. I don't know. I'm just guessing from what little you've said.

You may want to make yourself clearer. You don't want to go off at a tangent without explaining why if you want me to come with you.
Mar 21 '11 #5
garfieldsevilla
37 New Member
hi NeoPa, I understood what you were saying in #2 and decided not to proceed with VBA in the report load control.

Rather, it seemed easier to filter the contents of the subform using a query with a funtion in the criteria (WHERE). So, I removed the VBA from the subform, added some VBA in a public function and a reference to this function in the query. When the query runs, a value is passed from the report and I decide whether or not to filter the record in the public function.

It turns out this query will be useful elsewhere and so is worth having.

The result now appears in a subreport on the report and the report has no VBA in the load control.

I have no idea how to achieve this using VBA in the report load control but have arrived at the required functionality another way.
Mar 21 '11 #6
NeoPa
32,556 Recognized Expert Moderator MVP
That sounds like you have what you need anyway. Excellent.
Mar 21 '11 #7

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

Similar topics

1
by: JJMM | last post by:
Hi, I have a form (form1) with a large number of subforms inside it (around 20 subforms), There is the possibility of filtering the data using a pop-up form that create/change a query (all the...
0
by: Arnold | last post by:
Hi there, I have a form to organize bottles in mind, but am unsure if it will work. Here's some background info: Mainform = frmProduct, which contains fields for pricing, status, etc. of...
8
by: Zlatko Matiæ | last post by:
Hello. How can I synchronize subforms content with current record in master form, if both form and subform are based on DAO code ? I assigned DAO recordset to forms by using QueryDef, on Load...
0
by: Mclaren | last post by:
Hi I have 3 tables: User, Customer and Customer order. I have a query that picks up all the orders captured for a given User. Each of the orders have a capture date. My main form is...
3
RobH
by: RobH | last post by:
I need to make a quotation report which will need to bring in different subForms/Reports. The problem I have is that if the content of the subform is longer that the area allocated it truncates the...
9
by: frys | last post by:
Access 2003 Windows XP I have a form that is for tracking attendance at programs. the main form is the program information, and the sub form is the attendance information. I have 5 homes...
4
by: Rich P | last post by:
Maybe you could try using a query as the recordsource for your subforms and for the criteria field in the query you could use a Form parameter. This way - instead of using the form filter property...
2
by: poteatc | last post by:
I want to filter my reports according date and time. I am already successful with filtering dates and times, but not overnight. I want to filter according to a shift that starts for example,...
3
by: zandiT | last post by:
Hello I have an access report and im using a query to filter the report using Date parameters eg Start Date-12 May 2009 and End Date-30 September 2009. the query works perfectly. My problem is...
4
by: kcropper | last post by:
Hi, I’ve been trolling these forums for a while now, and while I’ve found other related threads (e.g., http://bytes.com/topic/access/answers/702416-search-code-how-filter-using-code-sql), nothing has...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.