473,402 Members | 2,046 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,402 software developers and data experts.

Multiple filter options using unbound checkboxes

Hi
I have a database that holds recipes and I would like to be able to filter, in or out, certain ingredients.
For example show all recipes containing chicken or filter out all recipes containing nuts. I would also like to be able to filter with multiple criteria such as show all beef dishes that do not contain tomato, etc.

Each recipe has checkboxes to record which categories it should be included in and I have been trying to use unbound checkboxes in the header of a continuous form to mach these categories for filtering.

I can happily include or exclude one category like this.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub chk_ExChicken_Click()
  2. If Me.chk_ExChicken = -1 Then
  3.     Me.Filter = "([Rec_Chicken] = False)"
  4. ElseIf Me.chk_ExChicken = 0 Then
  5.     Me.Filter = ""
  6. End If
  7. Me.FilterOn = True
  8. End Sub 
But I can't work out how to make the filter more complex to allow for the 10 criteria I would like to filter in or out. I have a nasty feeling that it may be too much for my limited programming ability but was hoping that someone may be able to help me by explaining it as simply as possible?

I hope I have explained things appropriately and am very appreciative of any help that can be offered.

Thanks
Nov 8 '14 #1
9 3909
I've posted in the wrong place haven't I? Sorry :(
Nov 8 '14 #2
twinnyfo
3,653 Expert Mod 2GB
Hurumpf,

Nope, looks like you posted in the right place.

Before I move forward, I would like to ask how your tables are built?

In your block of code, it looks like there is a field in your table called Rec_Chicken. This implies to me that there are fields in each recipe for the type of ingredient?

Your recipes should have a table which holds all the data specific to just the recipe (RecipeName, Author, Instructions, PrepTime, etc.), and then you should have another table of just ingredients, which could hold information such as IngredientName, Calories, Cost, etc.). Then you have another table for all measurements. You have afinal table which marries those tables together, which would refer to the Recipe Table, and have a record for each ingredient and measurement used for that ingredient. Please refer to this thread for additional insight (Database Normalization)

This will not solve your immediate problem, but may help in the long run in designing your DB.

We can still address your desire to filter multiple ingredients.
Nov 12 '14 #3
Thanks for the advice. I am in the process of building the database now so I will rebuild the tables as per your recommendations and have a look at the link. It will most likely avoid other issues later down the line when it would be much harder to do anything about it.
Essentially the desire to filter ingredients in and out comes from the need to speed the process of putting dietary plans together for clients. If I can filter out things that people don’t like or are allergic to and filter in things they like best, I can highlight suitable recipes easily and work from them.
Any insight you can give would be most helpful. I am mostly self-taught with regards to access and so unfortunately my teacher is pretty poor!
Thanks.
Nov 13 '14 #4
twinnyfo
3,653 Expert Mod 2GB
I am self-taught, too. My teacher must be a moron!

:-)
Nov 13 '14 #5
twinnyfo
3,653 Expert Mod 2GB
As I am considering your question, it is one that I have come across, but have never had to actually use it. My initial thought is that we will have to build a query programmatically and use that query as the record source for another Form.

Some of the other experts may have more experience with this type of query building, but I am glad to work through details and learn with you.

The basic concept will be to have a Form that establishes your search criteria, then build a query that finds all recipes that meet all those criteria (e.g. Give me all recipes that use chicken but without using curry or paprika).

The concept is pretty simple, but the details behind it can be pretty complex, because you have recipes that contain several different ingredients. I've been playing with the concept in my free time, today...
Nov 13 '14 #6
Now that the ingredients are going to be in their own table it strikes me that I could probably filter using that table via unbound list boxes rather than a restricted set of tick boxes. That way if new ingredients are added they are automatically included in the filter. Does this sound like a better idea or am I making it more complicated?
Nov 14 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Hurumpf,

Now that the ingredients are going to be in their own table it strikes me that I could probably filter using that table via unbound list boxes rather than a restricted set of tick boxes. That way if new ingredients are added they are automatically included in the filter. Does this sound like a better idea or am I making it more complicated?
Keep in mind that "more complicated" doesn't necessarily mean bad. It is probably the "correct" way to create such a set of filters.

Although this would also "complicate" things, have you thought about having an "IngredientType" field in your Ingredients Table (along with an IngredientType Table)? This could list the type of ingredient it is, such as "Meat", "Dairy", "Spices", Vegetable", etc. This would also allow you to choose, for example, vegetarian recipes, or recipes without Dairy (or both). Again, this highly complexifies the entire project. It just depends on how much work you are willing to put into this project.

Just as an aside, even though the thought of creating a challenging recipe database appeals to my OCD tendencies, were there no good off-the-shelf recipe programs available? Many of these have such filters built in.....
Nov 14 '14 #8
I had a look at the off the shelf software and it's way out of my price range. I am happy to spend time on this I just don't think I have the skills :(
Spent around 5 hours this morning looking at forums and trying different bits of code. I can happily filter in or out from an unbound combo box in the form header but I can't combine boxes to filter 1 ingredient in and one out, and I can't filter for more than 1 ingredient at a time.
I have tables for the recipe, for the ingredients and for the ingredient category as advised.
I made a query to show the recipes and the ingredients in a continuous form and tried to do all my filtering from there.
I tried using 1 unbound combo box to draw ingredients into different unbound textboxes and then pointing the filter at those boxes like this. (got the code from a Google search and tried to change it to suit... and failed. It filters the first criteria only and then returns no records after that. Maybe because I am trying to do it all on one field???)
Expand|Select|Wrap|Line Numbers
  1.  Private Sub btn_Filter_Click()
  2. Dim strFilter As String
  3. strFilter = ""
  4. If Me!txt_Out1 & vbNullStr <> vbNullStr Then
  5.    strFilter = strFilter & "AND [Ing_Ingredients] = '" & Me.txt_Out1 & "'"
  6. End If
  7. If Me!txt_Out2 & vbNullStr <> vbNullStr Then
  8.    strFilter = strFilter & " AND [Ing_Ingredients] = '" & Me.txt_Out2 & "'"
  9. End If
  10. If Me!txt_Out3 & vbNullStr <> vbNullStr Then
  11.    strFilter = strFilter & " AND [Ing_Ingredients] = '" & Me.txt_Out3 & "'"
  12. End If
  13. If strFilter <> "" Then
  14.    Me.Filter = Mid(strFilter, 4)
  15.    Me.FilterOn = True
  16. Else
  17.    Me.Filter = ""
  18.    Me.FilterOn = False
  19. End If
  20. End Sub 
So I can filter everything that contains chicken or I can filter everything that doesn't contain chicken.
I can't filter everything that contains chicken and carrot
I can't filter everything that contains chicken but not tomato

My brain hurts.
Nov 15 '14 #9
twinnyfo
3,653 Expert Mod 2GB
Sorry it's taken a while to respond. I believe you will have to build a filter string on the fly that includes joins with other queries built on the fly. I am not at my pc right now, but I have played around with it a little recently. The basics are that you create a query that lists all the recipes that use chicken for example. Now if you want all recipes that don't use chicken, you create another query that left joins that query with the chicken query and set the criteria to be null at the join field

This may not make much sense in writing, but I can't write the exact code off the top of my head. I will try to return to this tonight if I get a chance.
Nov 19 '14 #10

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

Similar topics

2
by: ggk517 | last post by:
I have a script like below: ------------------------------------------------------------------------------------------------------------------------ <html> <head> <title>TEST</title> <script...
1
by: Cara Murphy | last post by:
Hi There! Hoping you are able to help me with a filtering scenario: I have created a pop up form (Filter) to filter a report (Open Issues), which currently has a number of combo boxes which...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
3
by: angi35 | last post by:
Working in Access 2000... I have a form with records for every employee. I'd like to create two command buttons so a user can filter the form for either 'only current' or 'only former' employees. I...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
5
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
3
by: simple simon | last post by:
How would I insert into multiple related tables using a table valued parameter? Is there any way to do this without using a WHILE loop? I know how to insert from a table valued parameter into one...
5
by: mahirinku | last post by:
how to add new more options in select box options using JavaScript . Please tell me what i do for add more options in options box using JavaScript .
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
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...
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
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.