Re: Why Checkbox count = 4



Thanks Tom:

Your code produces in my immediate window:

1 OptionButton1
2 OptionButton2
3 CheckBox1

And my Msgbox for Checkboxes indicates 3;

But there is ONLY 1 !!



"Tom Ogilvy" wrote:

Add a debugging statement

Private Sub CommandButton1_Click()
For Each ctl In UserForm1.Controls
If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1
If TypeOf ctl Is MSForms.Frame Then Framect = Framect + 1
If TypeOf ctl Is MSForms.CheckBox Then
CkBoxct = CkBoxct + 1
debug.print CkBoxct, ctl.name
end if
If TypeOf ctl Is MSForms.TextBox Then Txtct = Txtct + 1
If TypeOf ctl Is MSForms.OptionButton Then OptBnct = OptBnct + 1
If TypeOf ctl Is MSForms.ComboBox Then ComBoxct = ComBoxct + 1
Next ctl
MsgBox "labels total " & labelct
MsgBox "Frame total " & Framect
MsgBox "Checkboxes total " & CkBoxct
MsgBox "Textboxs total " & Txtct
MsgBox "OptionButtons total " & OptBnct
MsgBox "ComboBoxs total " & ComBoxct
End Sub


See the results in the immediate window in the VBE (view=>Immediate window
if it isn't already visible)
--
Regards,
Tom Ogilvy

"JMay" wrote:

JE,
When I (in the immediate window) enter your suggested

?UserForm1.Controls.Count

I get the right total count -- But still a Checkbox Overcount;
I'm still working on.. I'll report back if I CRACK..

No Checkboxes ARE HIDDEN

Tks,

Jim


"JE McGimpsey" wrote:

At the risk of offending, are you sure that there aren't checkboxes
hidden by other controls (perhaps frame(s)?)?

If you execute

?UserForm1.Controls.Count

in the immediate window, do you get the correct total?

In article <9049AF53-701F-4AA1-B39E-FCD6301D866E@xxxxxxxxxxxxx>,
JMay <JMay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

attempting to better understand the use of TypeOf I have created:
All message boxs return the proper number, except the CkBoxct,
which returns 4, when IN FACT there is only 1 Checkbox on my Userform1.
Any ideas why this problem?
TIA,
Jim May

Private Sub CommandButton1_Click()
For Each ctl In UserForm1.Controls
If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1
If TypeOf ctl Is MSForms.Frame Then Framect = Framect + 1
If TypeOf ctl Is MSForms.CheckBox Then CkBoxct = CkBoxct + 1
If TypeOf ctl Is MSForms.TextBox Then Txtct = Txtct + 1
If TypeOf ctl Is MSForms.OptionButton Then OptBnct = OptBnct + 1
If TypeOf ctl Is MSForms.ComboBox Then ComBoxct = ComBoxct + 1
Next ctl
MsgBox "labels total " & labelct
MsgBox "Frame total " & Framect
MsgBox "Checkboxes total " & CkBoxct
MsgBox "Textboxs total " & Txtct
MsgBox "OptionButtons total " & OptBnct
MsgBox "ComboBoxs total " & ComBoxct
End Sub

.



Relevant Pages

  • Re: Why Checkbox count = 4
    ... And my Msgbox for Checkboxes indicates 3; ... If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1 ... CkBoxct = CkBoxct + 1 ... MsgBox "Checkboxes total " & CkBoxct ...
    (microsoft.public.excel.programming)
  • Re: Why Checkbox count = 4
    ... All message boxs return the proper number, except the CkBoxct, ... If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1 ... MsgBox "Frame total " & Framect ... MsgBox "Checkboxes total " & CkBoxct ...
    (microsoft.public.excel.programming)
  • Re: Why Checkbox count = 4
    ... Private Sub CommandButton1_Click ... If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1 ... CkBoxct = CkBoxct + 1 ... MsgBox "Frame total " & Framect ...
    (microsoft.public.excel.programming)
  • Re: Why Checkbox count = 4
    ... If TypeOf ctl Is MSForms.Label Then labelct = labelct + 1 ... CkBoxct = CkBoxct + 1 ... MsgBox "Frame total " & Framect ...
    (microsoft.public.excel.programming)
  • RE: Validating at least 1 ck box is checked
    ... invisible textboxes totaling the values of the checkboxes in each area, ... and then basing the MsgBox on a sum of other than 0. ... I can't allow them to exit without saving. ... This is the code, and you can see that "Cancel = True" is in there, but it ...
    (microsoft.public.access.formscoding)