473,549 Members | 2,741 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 15942
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
3546
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...
1
4197
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
2535
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...
2
3744
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
1795
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...
1
3089
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
2935
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
2683
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...
3
4705
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
7720
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. ...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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...
0
5088
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...
0
3500
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...
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.