473,900 Members | 4,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processing Multiple Check Boxes

I'm having dificulty figuring out how to process multiple check boxes on a
web form.

Let's say I have three check boxes:
cbox1
cbox2
cbox3

The only way I can think of to code the possibilities is something like:

If cbox1.checked = true then
..........
End if

If cbox2.checked = true then
.......
End If

If cbox3.checked = true then
.......
End if

If cbox1.checked = true and cbox2.checked = true then
.......
end if

If cbox1.checked = true and cbox3.checked = true then
.......
end if

And the If/End IFs go on forever!

As you can see, if I have around 8 check boxes, doing it this way could lead
to tremendous amounts of coding. I'm sure there's a better, easier way,
right? I thought of using a select case but that wouldn't be much better I
don't think.

The application is a query that runs against a single table in an access
database. Each check box represents each field they could chose from to show
up in a table or other style report.

TIA,
Jim

Nov 21 '05 #1
10 15994
Why not do something like:

dim c as integer = 0
if cbox3.Checked = True then c = 1
if cbox2.Checked = True then c += 2
if cbox1.Checked = True then c+=4

Select Case c
Case 0 'No checks
Case 1 'cbox 3
Case 2 'cbox 2
Case 3 'cbox 2 & 3
Case 4 'cbox 1
Case 5 'cbox 1 & 3
Case 6 'cbox 1 & 2
Case 7 'cbox 1,2, & 3
End Select

Yeah, it's archaic...but I come from an Applesoft Basic background :)

"Jim in Arizona" <ti*******@hotm ail.com> wrote in message
news:OW******** ******@TK2MSFTN GP10.phx.gbl...
I'm having dificulty figuring out how to process multiple check boxes on a
web form.

Let's say I have three check boxes:
cbox1
cbox2
cbox3

The only way I can think of to code the possibilities is something like:

If cbox1.checked = true then
.........
End if

If cbox2.checked = true then
......
End If

If cbox3.checked = true then
......
End if

If cbox1.checked = true and cbox2.checked = true then
......
end if

If cbox1.checked = true and cbox3.checked = true then
......
end if

And the If/End IFs go on forever!

As you can see, if I have around 8 check boxes, doing it this way could
lead to tremendous amounts of coding. I'm sure there's a better, easier
way, right? I thought of using a select case but that wouldn't be much
better I don't think.

The application is a query that runs against a single table in an access
database. Each check box represents each field they could chose from to
show up in a table or other style report.

TIA,
Jim

Nov 21 '05 #2
"Jim in Arizona" <ti*******@hotm ail.com>'s wild thoughts
were released on Tue, 19 Jul 2005 16:21:09 -0700 bearing the
following fruit:
I'm having dificulty figuring out how to process multiple check boxes on a
web form.

Let's say I have three check boxes:
cbox1
cbox2
cbox3

The only way I can think of to code the possibilities is something like:

If cbox1.checked = true then
.........
End if

If cbox2.checked = true then
......
End If

If cbox3.checked = true then
......
End if

If cbox1.checked = true and cbox2.checked = true then
......
end if

If cbox1.checked = true and cbox3.checked = true then
......
end if

And the If/End IFs go on forever!

As you can see, if I have around 8 check boxes, doing it this way could lead
to tremendous amounts of coding. I'm sure there's a better, easier way,
right? I thought of using a select case but that wouldn't be much better I
don't think.

The application is a query that runs against a single table in an access
database. Each check box represents each field they could chose from to show
up in a table or other style report.


Then why do you need conditions such as

If cbox1.checked = true and cbox2.checked = true then...

Can't you just build up your query by checking each checkbox
in turn?


Jan Hyde (VB MVP)

--
Occult: A young horse. (Keith Nance)

[Abolish the TV Licence - http://www.tvlicensing.biz/]

Nov 21 '05 #3
Then why do you need conditions such as

If cbox1.checked = true and cbox2.checked = true then...

Can't you just build up your query by checking each checkbox
in turn?
Jan Hyde (VB MVP)

--
Occult: A young horse. (Keith Nance)

[Abolish the TV Licence - http://www.tvlicensing.biz/]


I'm still pretty new to programming so still trying to get some coding
techniques established. I've never worked with check boxes.

When you say "Can't you just build up your query by checking each checkbox
in turn?", I'm not sure what you mean. Can you give me an example?

Thanks Jan,
Jim
Nov 21 '05 #4
"Terry Olsen" <to******@hotma il.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Why not do something like:

dim c as integer = 0
if cbox3.Checked = True then c = 1
if cbox2.Checked = True then c += 2
if cbox1.Checked = True then c+=4

Select Case c
Case 0 'No checks
Case 1 'cbox 3
Case 2 'cbox 2
Case 3 'cbox 2 & 3
Case 4 'cbox 1
Case 5 'cbox 1 & 3
Case 6 'cbox 1 & 2
Case 7 'cbox 1,2, & 3
End Select

Yeah, it's archaic...but I come from an Applesoft Basic background :)


That's an interesting approach. My head is swimming a bit looking at it
though. I like the idea and, if I can't find something else I can fuse into
my head easier, I will definately give it a go.

Thanks Terry,
Jim
Nov 21 '05 #5
"Terry Olsen" <to******@hotma il.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Why not do something like:

dim c as integer = 0
if cbox3.Checked = True then c = 1
if cbox2.Checked = True then c += 2
if cbox1.Checked = True then c+=4

Select Case c
Case 0 'No checks
Case 1 'cbox 3
Case 2 'cbox 2
Case 3 'cbox 2 & 3
Case 4 'cbox 1
Case 5 'cbox 1 & 3
Case 6 'cbox 1 & 2
Case 7 'cbox 1,2, & 3
End Select


Hi Again Terry.

Going over your example and putting it to work with 7 check boxes, I would
get this then?

if cbox7.checked = true then c = 1
if cbox6.checked = true then c += 2
if cbox5.checked = true then c += 4
if cbox4.checked = true then c += 8
if cbox3.checked = true then c += 16
if cbox2.checked = true then c += 32
if cbox1.checked = true then c += 64

So, there would be a possible .. how many CASEs is that, 128? :) That's a
cool way of doing it although a still a bit tedius. I can't imagine any way
that isn't tedius though!

I'm just trying to get the math down. In your example, are you doubeling
each box down the line (ie: 1, 2, 4, 8 ...)? That seems right to me.

Any idea of how I could more easily code 128 Cases?

The Case statement would be executed when a submit button is clicked. The
first thing that would happen is a connection to a database. The next would
be the command object/sql statement. Each case would have to be its own SQL
statement "SELECT " & cbox7.text " FROM Table1". Would the be some kind of
easier way .. like, I don't know, making up some kind of array and looping
through it? I'm just shooting in the dark here.

A co-worker and I are trying to work up an idea using stored procedures but
I'm not sure if we're going to succeed there or not.

If there is no other way, then I'll just have to code all 128 of 'em. :)

Thanks,
Jim
Nov 21 '05 #6
"Jim in Arizona" <ti*******@hotm ail.com> wrote in message news:On******** *****@TK2MSFTNG P09.phx.gbl...

The Case statement would be executed when a submit button is clicked. The
first thing that would happen is a connection to a database. The next would
be the command object/sql statement. Each case would have to be its own SQL
statement "SELECT " & cbox7.text " FROM Table1". Would the be some kind of
easier way .. like, I don't know, making up some kind of array and looping
through it? I'm just shooting in the dark here.

A co-worker and I are trying to work up an idea using stored procedures but
I'm not sure if we're going to succeed there or not.

If there is no other way, then I'll just have to code all 128 of 'em. :)

Thanks,
Jim


Here is what I would do. First, I would place all of the CheckBoxes in a GroupBox, perhaps named grpFields. I would then place the
field name in the Tag property of the CheckBox, but you could just use the Text. I would then loop through all of the controls on
the GroupBox and process each one that is a CheckBox with the Tag net an empty string and dynamically build the select statement.
It would look somerthing like:

Dim strSQL As String = "SELECT "
Dim bFirst As Boolean = True

For Each ctl As Control In grpFields.Contr ols
If TypeOf ctl Is CheckBox Then
If ctl.Tag <> "" Then
strSQL &= CStr(IIf(bFirst , "", ",")) & ctl.Tag
bFirst = False
End If
End If
Next

strSQL &= " FROM Table1"

At this point you can execut the SQL and return a recordset with the selected fields.

I hope this helps.

--
Al Reid
Nov 21 '05 #7
> Here is what I would do. First, I would place all of the CheckBoxes in a
GroupBox, perhaps named grpFields. I would then place the
field name in the Tag property of the CheckBox, but you could just use the
Text. I would then loop through all of the controls on
the GroupBox and process each one that is a CheckBox with the Tag net an
empty string and dynamically build the select statement.
It would look somerthing like:

Dim strSQL As String = "SELECT "
Dim bFirst As Boolean = True

For Each ctl As Control In grpFields.Contr ols
If TypeOf ctl Is CheckBox Then
If ctl.Tag <> "" Then
strSQL &= CStr(IIf(bFirst , "", ",")) & ctl.Tag
bFirst = False
End If
End If
Next

strSQL &= " FROM Table1"

At this point you can execut the SQL and return a recordset with the
selected fields.

I hope this helps.

--
Al Reid


Hi Al.

Since I'm doing a web application (web form), a group box, which is part of
system.windows. forms is not an option. Too bad I couldn't import the
namespace and use it anyway huh?

Thanks anyway though.

Jim
Nov 21 '05 #8
>
Since I'm doing a web application (web form), a group box, which is part
of system.windows. forms is not an option. Too bad I couldn't import the
namespace and use it anyway huh?


Well, you could use a Panel or Placeholder I believe...
Nov 21 '05 #9
I'm just trying to get the math down. In your example, are you doubeling
each box down the line (ie: 1, 2, 4, 8 ...)? That seems right to me.


Yes. Think Binary...

0 = 0
1 = 1
01 = 2
11 = 3
100 = 4
101 = 5
110 = 6
111 = 7

But for efficiency and the least amount of code, I like the other suggestion
of putting the controls in a Panel or Placeholder and then looping through
each control.
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3575
by: Adrian Parker | last post by:
I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a delete button. All the corresponding records will be deleted. But I'm running into difficulty... Right now the NAME property of each check box is the primary key of the corresponding record. Hence if I know which checkboxes are checked, I simply use DELETE using the NAME value.
1
4222
by: Harish Vaidya | last post by:
hi, i am trying to use multiple checkboxes. what is happening is once select check box its variable is not getting set. below is the code. what could be the problem? i am using python 2.0 thanks in advance ============= from Tkinter import * def TestCases():
3
2562
by: Tim | last post by:
Hello All! I'm having a difficult problem and I'm wondering if anyone can help. Here's the deal. I have a webpage with multiple forms on it. All of the forms have drop down boxes that when selected and the corresponding button is pressed, the user should be taken to a new website. However, since I have 41 forms and 41 corresponding checkboxes, I would
2
3767
by: Craig M | last post by:
Hi, I have a form, frmInvoices and a subform, frmInvoicesSub. On the parent form, i have a "print report" button, that prints a report depending on an ID on the parent form. Each record in the subform has a check box, "invoiced". Currently, my print report button has the folowing code:
2
1807
by: Cin | last post by:
I have a one-to-many relationship that I would like to convert to an unbound checkbox or radio buttons within a form. On form (pulls from tblEquipment) user can select one or all three choices from table luCategory. Instead of putting a subform within another subform, within another subform. Want to be able to put in checkboxes for each of the 3 choices so that all could be selected, but it would link to TblEquipmentCategory and...
1
3109
by: Jim in Arizona | last post by:
I'm having dificulty figuring out how to process multiple check boxes on a web form. Let's say I have three check boxes: cbox1 cbox2 cbox3 The only way I can think of to code the possibilities is something like:
1
2957
by: projectjakecs | last post by:
Hi, I am working on a ms access database and I am having trouble using a form to create new records in an associative table. Here is the breakdown of my database: Main Table - Computer Primary Key - ComputerID (AutoNumber) ComputerName
3
2698
by: LuCnt | last post by:
I am using Visual basic 6 and i want to be able to select more that one response in a option group with check boxes. As it is now i can only select one response at a time. the code looks like this. The option group is fractivities Private Sub FrActivities_Click() If Me.FrActivities.Value = 1 Then Cusactivities = " Running " End If If Me.FrActivities.Value = 2 Then Cusactivities = " Walking " End If If Me.FrActivities.Value = 3 Then
3
4722
by: Search & You Will Find | last post by:
I have a database in Access 2000 that I need some help on. I have three tables: PROJECTS, SYSTEMS, & SYSTEMSREF. They possess the following fields: ----------------------------------- PROJECTS project_pk (autonumber) project_name
0
9997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11277
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10866
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8045
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5892
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4305
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.