Dynamically build a query

Reppers

Registered User.
Local time
Today, 04:36
Joined
Oct 27, 2008
Messages
32
Me again!

This time I'm striding out WAY past my ability level, and was looking for someone to help me solve the problem, and help me learn!

Having rootled through the internet I think I need to build a dynamic query to get what I want, but if there's a simple way, I'd be even more grateful for that!

I have a table called tblYearData. It contains various information about a child in a given year - SchoolYear (yy/yy) their SENID (either 1, 2, 3, or 4), ClassID, and a variety of yes/no fields - ReadingRecovery, FreeMeals, SeriousCVA ....

I want to be able to populate a list of children with certain criteria, but not exclude children if they DON'T have something. It's simpler with a 'for instance'.

Child 1 - SENID = 1, ReadingRecovery = yes, FreeMeals = yes
Child 2 - SENID = 1, ReadingRecovery = yes, FreeMeals = no
Child 3 - SENID = 1, ReadingRecovery = no, FreeMeals = yes.

On the form, I would like the user to be able to check boxes for the groups they would like to look at and a combo box for SENID.

Using a regular query with each field corresponding to a checkbox, if the user selects SENID = 1 from a combo box but leaves the check boxes all unchecked, no children are returned. However, I would like all 3 returned, as they are all SENID =1.

If the user selected SENID = 1 and checked the reading recovery box, I want both child 1 and 2 returned as they are both in both those groups, irrespective of their freemeal situation.

As I said, perusing the internet, I got the idea that dynamically building an SQL query where if (for example) the ReadingRecovery box was checked - "And ReadingRecovery = True" would be added to the SQL clause, would solve the problem.

However, this is the extent of my understanding - taking this an making it work is another problem.

As ever, any help or thoughts would be greatly appreciated.
 
Mr B!

That's one of the sites I looked at previously - the one that led me to believe that building a dynamic query is the right way to go. The problem is, I have no real experience using VBA or writing SQL statements - everything I've done so far is cobbled together from bits of code I've found on the internet, and a LOT of trial and error!

Granted, that's not your problem and I am trying to learn, but this is a little out of reach on my own - I need a little guidance to get on the right track - any help?
 

Users who are viewing this thread

Back
Top Bottom