How to designate a query to run with a check box

Coach Ty

Registered User.
Local time
Today, 15:36
Joined
Aug 16, 2009
Messages
64
Hello,
I have a form that I've designed to input information into a table. This information will be used to run many queries to obtain calculated statistics.

On this for there are options that can be chosen by the user. These options will determine the formula query that will be run to obtain the desired stat.

On the form I've designated check boxes to the individual queries, to allow the user to check their option and subsequently run the proper query formula based on their option.

So, I was wondering what the proper procedure would be to design the system so that an individual query would be linked to a check box. Whereas, if the check box is chosen, with a check or is valued at "true", the system would run the query associated with that option. And if a check box wasn't checked the other queries would not be ran to return the desired stat.

Is there a way to link a query to a check box, so that when the box is checked, that specific query is ran?

Please let me know and thanks for your help.
 
Depending on the nature of the queries the checkbox value can be incorporated directly into the query.

The simplest example is returning records with a Y/N field set to true. Simply include the where phrase: WHERE mytable.fieldname = Forms!formname!checkboxname

This can also be done with more complex data using an IIF function. This would return fieldX is the checkbox is ticked or fieldY if not:
IIF(Forms!formname!checkboxname, fieldX, fieldY)

However this gets really messy in complex cases and instead the query would be constructed dynamically using VBA If statements or Case statements
Basically, if a box is checked then add a phrase to the WHERE clause.
 
Thanks for the reply.
My purpose for the question is for the following issue:
I'm developing a software program. In this instance there will be a contant value of time that will be input. The statistic value will be determined by the distance variable.
Whereas, the query formula that will be utilized to determine the statistic value will be determined by the distance used for the testing.

Lets say that we have one time to be input. The formula used to determine the score, will be based on the distance used to get the time.

So if we have several distance options, Distance A, Distance B, and Distance C.

The user would check the appropriate distance and enter the time.
If the time was achieved by using Distance A, the distance A box would be checked. The system would then insert the time into the formula associated with the Distance A option, to achieve the statistic score value.

So, in this case it sounds like the IIF expression, might be the best way to go. The score achieved will be subsequently used for other queries. So, if the box isn't checked, I would like it to return a "0" value rather than a null. So, the expression should be written to reflect that if the box is checked (a true value) the the filed should reflect the answer of the formula, and if the box is not checked it should return a value of "0".

Can you tell me how this IIF expression should be written?

Thanks again for your help!
 
IIF function
http://office.microsoft.com/en-us/access/HA012288531033.aspx

Use the Nz function to control the value if there if there is a null returned.
http://office.microsoft.com/en-us/access/HA012288901033.aspx

Maybe something like this:
IIF(Forms!formname!checkboxname, Nz({score expression}, {somevalue}), 0)

Note: Since the checkbox is a Y/N field it can usually be written directly without the comparison and means the same as:
Forms!formname!checkboxname = True

You might also want to think about any potential need for catching errors with the IsError function
http://office.microsoft.com/en-us/access/HA012288651033.aspx
 
Yes, I was thinking about using the NZ function.
Thank you very much for your help!
 

Users who are viewing this thread

Back
Top Bottom