UserForm Option Buttons and Check Boxes help please!

S

Starbird

I have built a template with a UserForm containing several options using text
boxes, radial buttons and check boxes. The text boxes work fine and I have
managed to get the UserForm to perform the function for the radial buttons
and check boxes upon opening the template and making the selection, however,
if option 1 is selected and the user decides to select option 2 instead, it
errors out because the function for option 1 already occured making the
second selection option impossible. I need to figure out how to tell my
document not to perform the action selected on the userform until the 'OK'
button is selected. Can someone lead me in the right direciton please!!!

I thought if I put the script in the "ThisDocument" section rather than the
"UserForms" section it would make more sense, but I can't figure out how to
make it work there either.

Thanks in advance for any help or insight.
 
J

Jay Freedman

If you're doing things in the document within the OptionButton1_Click
procedure and the other radio button click procedures, that's wrong.
You should do *all* actions that affect the document only in the
cmdOK_Click procedure, which fires when the user clicks the OK button
(assuming you renamed the button from CommandButton1 to cmdOK). You
don't need to have any code in the radio button click procedures.

When the OK button is clicked, your code should find out which radio
button has its Value equal to True -- only one of them will -- and do
the corresponding work in the document.

Private Sub cmdOK_Click()
If OptionButton1.Value = True Then
' do Option1 action in document
ElseIf OptionButton2.Value = True Then
' do Option2 action in document
ElseIf ...

End If

Unload Me
End Sub

It has nothing to do with which module the code is in. In fact, in
order for the click event to cause the code to execute, the code
*must* be in the userform.
 
S

Starbird

Thanks for your help Jay. I put my code in the cmdOK_Click and it works like
a charm!
I knew I wasn't far off, but I haven't written much script since the early
80's and things are a bit different now although most of the basics are the
same.

Thanks again!

SRD
 

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