Preloading value into Option Button

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

I have a a form with Option Buttons. I want to load the
form with one of its buttons at TRUE. The following below
does not work. The form loads with the option button
chosen. Whey is this

PrintHyperLinkOptionButton = True

UserForm1.Show

Thanks
 
Why not just use

Me.Optionbutton1.Value = True

in the Userform_Activate event?

But be aware, if you have a click event for that button, it will be
triggered.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
So just our of curiosity Bob. I have not been using a
Userform_Activation event. I have been calling the form
and attempting to set it up prior to the Call stmt as seen
below. Accordingly, I was going to follow through with
the PrintHyperLinkOptionButton = True at the bottom.
Should I move all of this into a Userform_Activation event?

Sub AuditCell()


UserForm1.CircularityChkBx.Enabled = False
UserForm1.InputsChkBx.Enabled = False
UserForm1.ExternalLinkChkBx.Enabled = False
UserForm1.UniqueFormulasChkBx.Enabled = False

UserForm1.PrintColourMapOptionButton.Enabled = False

UserForm1.ComboBox1.Enabled = False

UserForm1.UniqueFormulasAdjustChkBx.Enabled = False

PrintHyperLinkOptionButton = True

UserForm1.Show

End Sub
 
This doesn't seem to work:

Private Sub UserForm1_Activate()
Me.PrintHyperLinkOptionButton.Value = True
End Sub

Now I am still using the sub below and your refinement.
Cannot I not do this?

Sub AuditCell()


UserForm1.CircularityChkBx.Enabled = False
UserForm1.InputsChkBx.Enabled = False
UserForm1.ExternalLinkChkBx.Enabled = False
UserForm1.UniqueFormulasChkBx.Enabled = False

UserForm1.PrintColourMapOptionButton.Enabled = False

UserForm1.ComboBox1.Enabled = False

UserForm1.UniqueFormulasAdjustChkBx.Enabled = False

UserForm1.Show

End Sub
 
That's not a clear-cut question. I think you need to understand the order of
events and work out what is best for your app.

If you set the form as you are doing outwith the form module, then you
automatically load the form if it is not loaded, that is the form is loaded
into memory but not shown.

When you load the form, the Userform_Initialize event is triggered, so you
could put that code in Initialize if it is required to refresh whenever a
for is loaded.

When you show the form the Userform_Activate event is triggered. So you can
add code here that you want every time the form is shown (which you control
via code remember).

The problem (?) with doing it outwith the form module is that it is
effectively Initialize event when you might want it to be Activate event.

Generally speaking, I try to avoid setting the form from a standard code
module, preferring to do it from within the form module itself. Of course,
there are always exceptions, such as hiding (not unloading) a form and
testing a form public property from the standard code module to determine
next action.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
That is because the event is cal;led Userform_Activate. It is a form event,
not that form name event :-).

see my other response for the other bit.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Private Sub UserForm1_Activate

should be
Private Sub UserForm_Activate

using the generic Userform

If you select your events from the dropdown, you won't have this problem.
 
Is there a typo in your explanation?

setting an option button to true Selects it. As written, it sounds like you
have achieved what you desire?
 

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

Back
Top