View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Adding OptionButtons to array error 91

Thought I had found the mistake as it should be:

Set OptionButtons(i).objOptionButton = ctl

but still the same error.

RBS



RBS

"RB Smissaert" wrote in message
...
Have the following code to add OptionButtons to a control array:

A class called OptionButtonClass:

Option Explicit
Public WithEvents objOptionButton As MSForms.OptionButton

Private Sub objOptionButton_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Dim lContextHelpID As Long

If Button = 2 Then
On Error Resume Next
lContextHelpID = objOptionButton.HelpContextID
On Error GoTo 0
If lContextHelpID 0 Then
ShowHelp bWebHelp, lContextHelpID
End If
End If

End Sub

In a normal module:

Public OptionButtons(24) As OptionButtonClass

Sub AddOptionButtonsToArray(oForm As UserForm, lStart)

Dim ctl As MSForms.Control
Dim i As Long

i = lStart

For Each ctl In oForm.Controls
If TypeName(ctl) = "OptionButton" Then
OptionButtons(i).objOptionButton = ctl
i = i + 1
End If
Next

End Sub

The above Sub is called like this:

AddOptionButtonsToArray MainForm, 0

I get an error 91: Object variable or with block not set when initializing
the form MainForm
and the line where the problem is is:
OptionButtons(i).objOptionButton = ctl

No idea why this falls over as exactly the same principle works fine with
checkboxes and labels.
Any advice with this greatly appreciated.


RBS