?
Solved

Checking checkboxes to produce a SELECT statement

Posted on 2005-04-26
4
Medium Priority
?
188 Views
Last Modified: 2010-05-02
I have a list of checkboxes each one refering to a field in a query in an Access database,
I need to make it so that the user can build a query based on the boxes that they check. The only way I can think to do this is to write out about a million if statements to cover all possibilities. i.e.

if(chk1.value = vbchecked and chk2.value = vbunchecked and etc.. )then
do query
elseif(etc...)

there must be an easier way of doing this, I've got 9 check boxes, so doing as above would take a long time.

I would appreciate any suggestions

Thanks
0
Comment
Question by:liseperu
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
ShelfieldCollege earned 2000 total points
ID: 13865104
The way I did this was to build the quiery up bit by bit, e.g.

dim strQuery as string
dim inQuery as boolean

strQuery = "SELECT * FROM table"


if chk1.value then
  strQuery = strQuery & " WHERE (field=true"
  inQuery = TRUE
end if

if chk2.value then
  if inQuery then
    strQuery = strQuery & " AND field2=true"
  else
    strQuery = strQuery & " WHERE (field2=true"
    inQuery = TRUE
  end if
end if

... Continue for other check boxes...

if inQuery then
  strQuery = strQuery & ");"
end if

Hope this is what you meant, cheers.

Matt
0
 

Author Comment

by:liseperu
ID: 13865120
thats quite clever, thanks, that'll save me some time!!
0
 
LVL 4

Expert Comment

by:ShelfieldCollege
ID: 13865136
No problem at all :)
0
 
LVL 4

Expert Comment

by:ShelfieldCollege
ID: 13865140
Oh forgot to mention sorry, don't forget that last if statement, basically it closes the brackets off if you using the WHERE clause in the statement. :) Cheers

Matt
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question