Thanks Jay.
You mean if you remove the ' from this line of the code I posted you are not
getting a runtime error?
Dim oCheckboxArray() 'As CheckBox

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
>Thanks Jay.
>
>You mean if you remove the ' from this line of the code I posted you are not
>getting a runtime error?
>
>Dim oCheckboxArray() 'As CheckBox
Hmmm -- different day, different behavior. Weird.
Pasting your code as-is into a new userform, I get a compile error
"Method or data member not found" on the line
ActiveDocument.Range.InsertAfter oCheckboxArray(j).Name & " " &
oCheckboxArray(j).Caption & vbCr
with ".Name" highlighted. Sure enough, IntelliSense doesn't list Name
as one of the properties of oCheckboxArray(j), which is strange
enough. But it doesn't list Name as a property of oButtonArray(i),
either, but the compiler doesn't complain about that.
At any rate, the userform doesn't get far enough to generate a runtime
error.
Let me suggest a different approach. Instead of storing the controls
themselves in the arrays, just store their names and captions in
arrays of strings. This works:
Private Sub CommandButton1_Click()
Dim oButtonArray() As String
Dim oCheckboxArray() As String
Dim i As Long
Dim j As Long
Dim oControl As Control
For Each oControl In Me.Controls
If TypeOf oControl Is MSForms.OptionButton Then
ReDim Preserve oButtonArray(1, i)
oButtonArray(0, i) = oControl.Name
oButtonArray(1, i) = oControl.Caption
i = i + 1
ElseIf TypeOf oControl Is MSForms.CheckBox Then
ReDim Preserve oCheckboxArray(1, j)
oCheckboxArray(0, j) = oControl.Name
oCheckboxArray(1, j) = oControl.Caption
j = j + 1
End If
SkipRest:
Next oControl
For i = 0 To UBound(oButtonArray)
ActiveDocument.Range.InsertAfter oButtonArray(0, i) _
& " " & oButtonArray(1, i) & vbCr
Next i
For j = 0 To UBound(oCheckboxArray)
ActiveDocument.Range.InsertAfter oCheckboxArray(0, j) _
& " " & oCheckboxArray(1, j) & vbCr
Next j
Me.Hide
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Greg Maxey - 21 May 2006 18:33 GMT
Yes that works nicely. Thanks.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
>> Thanks Jay.
>>
[quoted text clipped - 53 lines]
> Me.Hide
> End Sub
> Thanks Jay.
>
> You mean if you remove the ' from this line of the code I posted you are
> not getting a runtime error?
>
> Dim oCheckboxArray() 'As CheckBox
This is a problem because the Word library has a CheckBox object as well as
the MSForms library. If you go to Tools References you will see that the
Word library is listed ahead of the Forms 2.0 library, which means that in
the event of a naming conflict, it is the Word library with takes
precedence. To get round this, you need to qualify the object type with the
library name, like this
Dim oCheckboxArray() As MSForms.CheckBox

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Greg Maxey - 22 May 2006 13:21 GMT
Exactly. Thanks Jonathan.