help with code that checks controls in frame (check boxes) and if none are checked, Then....

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
THis is on a userform for adding a new record on a worksheet.

I have a few 'checks' in place so that certain checkboxes or selections or entries must be added before the form can add the data and create the new record.

All of these checks works fine, except for one of them that checks the controls inside a frame. No matter even if some checkboxes are checked, I still get the warning telling me that no check boxes were checked... 🤔 What i need it to do is if any checkboxes are checked, then skip the warning and move on to checking the 'check' and so on...

Here is the code... (also, I have tried adding an 'else' in here and no matter where I have it it is it doesn't recognize it at all and even if checkboxes are 'checked', it still thinks none are checked and gives me the warning...

VBA Code:
' WARNING:  "YOU MUST select at least ONE CHECKBOX before the data is accepted!"
  Dim Cntrl As Object
  For Each Cntrl In fraDepts.Controls
    If TypeOf Cntrl Is MSForms.CheckBox Then
      If Cntrl.value = False Then
        fraDepts.BackColor = vbYellow
        MsgBox "You must select at least ONE CHECKBOX" & vbNewLine & "before a new employee can be added:"
        fraDepts.BackColor = &HC8DAC6
        Exit Sub
      End If
    End If
  Next

here is the userform, filled out as an example to show what it looks like before running the code (and the subsequent 'check' for checking the controls in the frame...) :
2022-10-19 17_43_05-add1-1-1.jpg ‎- Photos.jpg

and here it is after running the code (via clicking on the 'new employee information' command button: (and the code telling me that no checkboxes are checked, when they actually are...)
add2-2-2.jpg

thanks for any help! (y)
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Did you step through your code to verify that things are as you expect - especially when you do a T/F test?
I thought option buttons and check boxes on userforms are 'attached' to (are children of) the form, not the frame.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top