View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
39N 95W 39N 95W is offline
external usenet poster
 
Posts: 14
Default Problem with looping through userform controls

You said there are new computers? Just a shot in the dark, but are all the
necessary References set on these new computers?

I too could not duplicate your error (in Windows XP Pro SP 2, Excel 2002)

-gk-


"Jeremy Gollehon" wrote in message
...
The following code has been working for a few years with no problems. Now
that we've installed some new computers around the office there's a
strange
error happening. On the new computers, the TypeName of "MN_optOn" is read
correctly as OptionButton. However, when it goes through the TypeOf
statements it makes it into the MSForms.Checkbox block (incorrectly) and
throws an error (correctly). I've checked the references and they appear
to
be the same on all computers and they all have a reference to 'Microsoft
Forms 2.0 Object Library'. This one's got me baffled. Any help is greatly
appreciated.

Thanks.
-Jeremy

---------------------------------------------------------------------------
Private Sub UserForm_Initialize()
Dim ctl As MSForms.Control

Set colMCF_Events = New Collection
For Each ctl In Me.Controls
If ctl.Name = "MN_optOn" Then
Debug.Print TypeName(ctl)
End If
'Fill checkbox collection
If TypeOf ctl Is MSForms.CheckBox Then
Set ctlChkbox = New MCF_Events
Set ctlChkbox.Chkbox = ctl
colMCF_Events.Add ctlChkbox
End If
'Fill Option button collection
If TypeOf ctl Is MSForms.OptionButton Then
Set ctlOptButton = New MCF_Events
Set ctlOptButton.Optbtn = ctl
colMCF_Events.Add ctlOptButton
End If
'Fill combobox collection
If TypeOf ctl Is MSForms.ComboBox Then
Set ctlDropdown = New MCF_Events
Set ctlDropdown.Cbobox = ctl
colMCF_Events.Add ctlDropdown
End If
Next ctl

End Sub
---------------------------------------------------------------------------