View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Why Checkbox count = 4

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 ,
JMay 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