![]() |
|
#1
|
|||
|
|||
![]()
Hi guys
I'm trying to write a code that ensures at least one checkbox is ticked on a form. Any idea why it's not working? Code:
Dim oCtr As Control For Each oCtr In Me.Controls If TypeName(oCtr) = "CheckBox" And oCtr.Value = True Then 'CODE HERE Else MsgBox "You must tick at least one." Exit Sub End If Next Thanks a lot! James Last edited by macropod; 04-27-2021 at 03:27 AM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
![]()
You could use:
Code:
Private Sub CommandButton1_Click() Dim oCtr As Control Dim bChecked As Boolean For Each oCtr In Me.Controls If TypeName(oCtr) = "CheckBox" And oCtr.value = True Then bChecked = True Exit For End If Next If Not bChecked = True Then MsgBox "You must tick at least one.", vbCritical GoTo lbl_Exit End If 'a checkbox is checked so do stuff lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thanks so much, I'll try this out!
![]() |
![]() |
Tags |
checkbox |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Checkbox - toggle hide/unhide other checkbox - XMLMapping | GErl | Word VBA | 9 | 11-19-2020 03:15 PM |
Table cell auto-shading when checkbox ticked. | markt | Word VBA | 2 | 08-05-2020 06:13 AM |
Table cell auto-shading when checkbox ticked. | markt | Word | 2 | 07-10-2020 08:53 AM |
![]() |
DEsh | Word VBA | 2 | 10-06-2017 08:23 PM |
![]() |
derajlance | Word VBA | 1 | 05-13-2016 01:55 PM |