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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Boxes in Access 97 1

Status
Not open for further replies.

compactmad

Technical User
Aug 19, 2002
20
0
0
AU
I have a form that has 20 check boxes. The users are required to tick one or more check boxes to indicate what a call was about.

How do i make sure they tick atleast one box?
 
If you name your check boxes in sequence (CheckBox1, CheckBox2...CheckBox20), you could use something like:

Function MakeSure() as Integer
Dim i as Integer
For i = 1 to 20
MakeSure=MakeSure + Me("CheckBox" & i)
Next i
End Function

The function will return 0 if none selected, or -1...-20 if there are check boxes selected.

HTH

Dan
 
Sorry Danvlas .... Where do i enter this function to make it work.
 
Open the form in Design view
Go to View-Code
Paste everything
Open the form in normal view and try it.

Dan
 
Or you could try something like

x=0
For Each cb in me.checkboxes
x=x+cb.value
Next
If x<1 then
msgbox &quot;Tick a category&quot;
else
end if

This can be part of your confirm button sub

HTH Rgds
~Geoff~
 
xlbo: There is no collection named 'checkboxes', so me.checkboxes gives me an error.
However, you can loop through all controls on the form and check its type:

For Each myctr In Me.Controls
If myctr.ControlType = acCheckBox Then
x=x + myctr '.Value is optional, cause it's default
End If
Next

But what if there are more check boxes on the form???


Dan
[smile]
 
Then use an group / frame control
This will also make the coding easier - if you only have the 20 checkboxes in this frame control, the code would look like

For Each ctl In Me.frChkb.Controls 'frChkb is name of frame
x=x+ctl.value
Next
If x<1 then
msgbox &quot;Tick a category&quot;
else
end if

HTH
Rgds
~Geoff~
 
This will limit you to have only ONE check box ticked at a time...

Dan
[smile]
 
No - it'll only allow one OPTIONBUTTON, you can have as many TICKBOXES ticked as you want Rgds
~Geoff~
 
Could you send me an .mdb file with a form with such a frame?
danvlas@yahoo.com

Thanx in advance (I'll give you a star for it),

Dan
[thumbsup]
 
Dan - BIG apologies - I was working on the theory that activeX controls work the same in all office products - d'OH - should've known better. In excel, the frame control lets you have multiple tick boxes selected, in access, it appears, it does not. Your method would appear to be the only way to solve this Rgds
~Geoff~
 
Geez, you don't know how much I hate being right on this.
I thought I had missed it and I have always placed multiple check boxes surrounded by a rectangle to give the impression of a multi-selectable frame.

Dan
[thumbsup2]
 
Hi - been in and out of a few Access lists and it appears that there is no way of creating a multiselect frame
Again, sorry to have lead you up the garden path Rgds
~Geoff~
 
what am i doing wrong i opened the form in design view, i renamed the check boxes to CheckBox1 to 20,i pasted the code into view code as a new module but nothing seems to happen.

sorry i have only every used the macros in access and i don't have a great understanding of VB.[sadeyes]
 
You have to paste the code in form's module: open the form in Design view, go to View->Code and paste it there.
Pasting it into a new module[/] doesn't work.

Dan
[pipe]
 
Thank you very much Dan, with a little help from a friend it works like a gem.

Your a legend.

Thanks
Tanya [sunshine]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top