Reset option buttons

D

dsimcox

I have a survey with about 50 pair of option buttons (labeled "yes" and "no")

I have a Command Button that I want to program to clear all buttons (set
..Value to False)

I've tried a number of methods, but am unable to succeed. Here's my latest
try. Can someone help me out of the darkness please?

Private Sub CommandButton1_Click()

'Clears Opt Buttons
Dim oCnt As Control

For Each oCnt In Me.Controls
If TypeOf oCnt Is OptionButton Then
ActiveDocument.oCnt.Value = False
End If

Next
End Sub
 
D

dsimcox

Greetings to you Helmut - and thank you for your help today.

It was your post to another question that I used to get started on this.

I substituted your recommendation below, but when I run the procedure, it is
hanging up on
 
D

dsimcox

Oops! I accidently hit the Post button in the middle of my thought . . .

The procedure is hanging up on this line:

For Each oCnt in Me.Controls

I'm getting a Compile error: Method or datamember not found

The controls I am trying to clear are ActiveX versions from the Control
Toolbox.
I can do this in Excel VBA - using the OLEObject set - but apparently it is
different in Word.

Any suggestions would be appreciated, when you have time to respond.

Thanks again!
 
H

Helmut Weber

Hi,
with great many thanks to Martin Seelhofer.
(I didn't do anything but search for a solution.)
Hopefully, this works.

Sub test556()
Dim opt As OptionButton
Dim ishp As InlineShape
For Each ishp In ActiveDocument.InlineShapes
' consider ActiveX-controls only:
If ishp.Type = wdInlineShapeOLEControlObject Then
' get through to the ActiveX-control itself
Set opt = ishp.OLEFormat.Object
' finally adjust the value to false
opt.Value = False
End If
Next
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
D

dsimcox

Very kind of you to research this for me -

I copied the procedure and stepped through it, but hit a snag at

Set opt = ishp.OLEFormat.Object

Got a Run-Time error 13 - type mismatch error.

The option buttons are all created from the Control Tool Box - so I know I
am dealing with OLE objects. I'm investigating what the source of the
mismatch is - but Help is not offering any clues. If you have any ideas, I
would enjoy hearing from you again.

Thanks for being so helpful, Helmut.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top