Tutorials
Check boxes search
There are just two simple steps to follow in order to do this.
1. On your search form, make sure you name each of your checkboxes individually.
For example, you have three checkboxes on your form so the user can choose all the options he likes from Restaurants, Cafe's and Take Aways
You would name your checkboxes something along the lines of cbRestaurant, cbCafe and cbTakeAway respectively.
Each of the checkboxes should also be assigned a value that you can use in your query - cbRestaurant might have a value of Restaurant.
2. In the recordset builder where you need to use the value of the checkboxes in your SQL query, you would add a parameter for each checkbox and give it the relevant run-time value.
For example, the Restaurant checkbox run-time value might be
Request.Form("cbRestaurant")
Once that is set up, if the user checks the Restaurant checkbox and submits the form, the value held in cbRestaurant would be Restaurant - which would be used as the run-time parameter in your SQL query.
Notes
If you need to use checkbox values (0, -1 for Access or 0, 1 for SQL Server) instead of text values like the example above, you will need to replace the values your checkboxes. Use -1 or 1 for Yes and 0 for No. In your recordset you need to remove the single quotes around your variables (which you use for text based values).
Your SQL statement, in this case, might look like this:
SELECT *
FROM myTable
WHERE Restaurant = varRestaurant OR Cafe = varCafe OR TakeAway = varTakeAway
|
Variables |
Default Value |
Run-time Value |
|
varRestaurant |
0 |
Request("cbRestaurant") |
|
varCafe |
0 |
Request("cbCafe") |
|
varTakeAway |
0 |
Request("cbTakeAway") |
© Copyright 2008 - robgt.com

