max number of check boxes allowed

difranco

New member
Local time
Today, 20:29
Joined
Dec 1, 2000
Messages
9
I have 15 check boxes on this form. The user may only choose up to five. How do make it so that if a user checks a sixth box, it does not get checked? (msgbox, no check) Do I have to dim, set, declare the checkboxes and then write an if then or select case statement? If yes or no, could anyone give me a hand on the code?
Thanks
 
Hi,
Give this a try:

'************************

Dim chkno As Integer 'hold checkbob count
Dim Answer As Variant
Dim ctl As Control
chkno = 0
For Each ctl In Controls
If ctl.ControlType = acCheckBox Then
If ctl.Value = True Then
chkno = chkno + 1
End If
End If
Next


If chkno <= 0 Then
Answer = MsgBox("There are NO Check
Boxes Selected" & Chr(13) & Chr(10) _
& "You MUST Select at least 1 " & Chr(13) & Chr(10) _
& "And a Maxium of 5 to Continue", vbOKOnly & vbCritical, "No Criteria Selected")
If Answer = vbOK Then
chkno = 0
Exit Sub
End If
End If


If chkno > 5 Then
Answer = MsgBox("Too many selections checked", vbOKOnly & vbCritical, _
"Too Many Criteria Checked")
If Answer = vbOK Then
chkno = 0
Exit Sub
End If
End If
' *****************************
I only used a vbOK in the msgbox, use whatever is
appropriate for your app.

HTH
Skip
 
Thank you. Actually I had posted this a while ago. I have moved onward and upward. I am close to getting this app completed. I just have a few more things to work on. I was almost set with this onopen statement of the form, but now it is all screwed up. The idea is that I need to det two option groups on the form to null --> ME![opgrp] = Null
and to fields to where I want them, so that the form will show that record on start up.
Me! [LT]= "06"
Me! [LT] = "001"
This was working for a while when there was a DoCmd.GoToRecord in the first line. Then the goto stopped working and the form could not match the code to the statment. Ahhhh. I am still trying to figure out how I can set this form on open to have those settings of null option groups and the record showing at the first one. If you can help here, that would be great.
Thanks
 
Hi
In your forms openevent put:

Me!optiongroupname.defaultvalue = ""

Skip
 
Thanks, I will give it a try. Sorry, I did not reply til now, I had to take a break for a couple of days. I had db overload!
 

Users who are viewing this thread

Back
Top Bottom