473,382 Members | 1,447 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,382 software developers and data experts.

applying a filter to a form that has a subform

Hi - I have a form called Vendor (tied to table with same name). Each vendor_id can belong to more than one 'category'. So there's a table called Vendor_Category which contains just vendor_id and category.

On the Vendor form, there's a subform called Vendor_Category. When a user is in the Vendor form and is in a record for a particular vendor_id, they use a combo_box in the Vendor_Category subform to select Vendor_Categories that can belong to the Vendor in question.

That works fine, but now I want to filter by Vendor_Category and just see vendor records the belong to a certain category. So I added an unbound vendor_category combobox which just contains a list of all the different categories. When a user selects one from the list, I've added code in the AfterUpdate that I want to use to set the filter.

Unfortunately, I have no clue how to write the filter. I know I set the filter and then turn the filter on. But the syntax is a mystery to me.

Any help would be greatly appreciated.

Thanks,
Bill
Aug 27 '09 #1
13 2085
ChipR
1,287 Expert 1GB
The Form.Filter Property is just like a Where Condition, so something like:
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "[Category] = '" & cboVendorCategory & "'"
  2. Me.FilterOn = True
Aug 27 '09 #2
Hi and thanks,

The part that's giving me trouble is the [Category] section in your example. When the event runs, it opens up a dialog box asking for the parameter value.

When I'm putting in the code and I put the field in as [category] with lower space, it doesn't recognize it and change it to uppercase. I thought maybe it was because it was on a subform, but even when I put in a field from the main form, it still doesn't change to upper case.

Note the following information:
1. Main form name is "Vendor". It's Record Source is the "Vendor" table. "Vendor_ID" is the primary key.
2. Sub_form name on the main form is called "Vendor_Category_sub". The Source Object for the subform is the form "sub_Vendor_Category". The Link Child and Link Master fields are both "Vendor_ID".
3. On the form "sub_Vendor_Category", the Record Source is the "Vendor_Category" table which contains only "Vendor_ID" and "Vendor_Category" fields. The "Vendor Category" field is what I'm trying to filter on.
4. The combo box on the "Vendor" form that I'm using to trigger the filter is called "Vendor_Category_Filter".

Just wanted to be thorough. I've checked to see if the [vendor_category] name was duplicated somewhere, but I can't find another instance.

Thanks again for any future help.
Aug 27 '09 #3
ChipR
1,287 Expert 1GB
[Category] in the code should be replaced with the name of the field in the main form's underlying recordset.
Aug 27 '09 #4
yes, did that. Here's my actual code

Me.Filter = "[vendor_category] = '" & Me.Vendor_Category_Filter & "'"
Me.FilterOn = True
Aug 27 '09 #5
ChipR
1,287 Expert 1GB
If it's still asking for a parameter value, then "vendor_category" is not the name of a field in the recordset you are trying to filter.
Aug 27 '09 #6
Agreed. The field name is definitely "vendor_category". But as it's on a sub-form, somehow it must not be part of the recordset? If I change the name to a field on my Vendor form such as "vendor_name" for instance, it recognizes it fine.

Either i'm referring to the field wrong (by not referencing the sub_form name) or the recordset needs to be expanded to include the data in the sub form and i don't know how to do that.
Aug 27 '09 #7
ChipR
1,287 Expert 1GB
To filter the subform, you would use:
subformControlName.Form.Filter = ...
Aug 27 '09 #8
Here's what I wrote. It now says 'Object Required' in the debugger. Maybe I don't know how to reference the [vendor_category] field correctly as it is also in the subform...

Vendor_Category_sub.Form.Filter = "[vendor_category] = '" & Vendor_Category_Filter & "'"
Vendor_Category_sub.Form.FilterOn = True
Aug 27 '09 #9
ChipR
1,287 Expert 1GB
Make sure that Vendor_Category_sub is the name of the control on the main form.
Aug 27 '09 #10
Thanks.

Well, it wasn't. Now it is. Now the filter works without an error, but the intended result isn't happening.

The sub-form now only shows the category chosen in the filter, but the main form still shows all records. Maybe I didn't explain properly, but I want to only see records on the main form that have a category matching the filter.
Aug 27 '09 #11
ChipR
1,287 Expert 1GB
I see the problem. You can't filter the main form on the category field because it isn't in the vendor table, which is what the error said. See if you can do:
Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "[VendorID] IN " _
  2.   & "(SELECT [VendorID] FROM VendorCategory WHERE " _
  3.   & "[category] = '" & cboVendorCategory & "')"
Aug 27 '09 #12
beautiful !!!!

thanks so much!
Aug 27 '09 #13
ChipR
1,287 Expert 1GB
Glad it works, and sorry I didn't read your initial post more carefully.
Aug 27 '09 #14

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

Similar topics

1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
4
by: MS | last post by:
I'm having trouble applying a filter to a subform. I create a String in a Module based on various selections on the form. Clicking a button on the "stand alone form" that changes the filter...
3
by: dhowell | last post by:
In reading some of the posts on this group, it appears as though it is not strait forward at all to filter a form, which has subforms, by criteria which are either on subforms or span more than one...
1
by: jcf378 | last post by:
Is it possible to set a main-form with an embedded subform to "Filter by Form", subsequently enter the desired variables in fields in BOTH the main-form and subform, and then save the resulting...
2
by: jambonjamasb | last post by:
What I am trying to do is have a combo box which allows me to filter for a certain field in a subform. I can't think how to do this and have tried with the follwoing code. Basically the field in...
9
by: angi35 | last post by:
Hi - In Access 2000, I have a form I want to filter, but I can't get the syntax right in the code. Form: Subform: Control on : txtStart Nested Subform on : Control on : txtSDate
0
by: diogenes | last post by:
"Rick Brandt" <rickbrandt2@hotmail.comwrote in news:bPnKj.456$%41.325 @nlpi064.nbdc.sbc.com: I used this approach, and it works a treat! ID In(SELECT Order_ID FROM orderitems WHERE NAME =...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.