Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Ad-Hoc Checkboxes

Status
Not open for further replies.

wbwillson

Technical User
Oct 7, 2002
52
GB
I have a form, and on that form I have 31 Checkboxes. The idea is that the user will check the boxes for the fields he/she would like to see on a report. I'm trying to create an "Ad-Hoc" report system. How can i programmatically determine the value of the checkboxes. I know I can do it the really long way like:

If chkLastName.Value = -1 Then
chkValue = "Last Name"

but since there are so many of them (31) the combinations are huge... Is there a way to determine if none of the values are checked but one or two are?

Sorry, I'm a bit of a newbie to VBA, I appreciate any help. Thanks

Bill

 
The easiest way to check lots of controls is in a loop:

If they are all sequentially named then:

for x=1 to 31
if me.controls("check" & x).value=true then
intCountofChecks=intCountofChecks+1
end if
next x

or you could use:

dim ctl as control
for each ctl in me.controls
if typeof ctl is checkbox then
intCountofChecks=intCountofChecks+1
end if
next ctl

this will count the number of checked boxes.

if you want to set a particular variable based on whether or not the box is ticked you will need to use something like:

eval(ctl.tag=true) (I think! will check it later!)

shout if you need any more help.

B ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Ben,

Thanks for the info! Once I fiqure out if the control is true or fale (o, or -1) is there a way I can determine that controls name. Example, if the chkLastName.value = -1 the I'd like the name of the control display (chkLastName)? Any thoughts? Thanks again for your help!

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top