Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding OptionButtons to array error 91
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding OptionButtons to array error 91
Now forget about this. It was indeed a simple mistake.
It should be: Public OptionButtons(24) As New OptionButtonClass Just had left New out and all working fine now. 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Choosing Only One Of Three OptionButtons | Excel Programming | |||
Array of OptionButtons ? | Excel Programming | |||
OptionButtons | Excel Programming | |||
Add OptionButtons in Excel | Excel Programming | |||
optionbuttons | Excel Programming |