Initializing Userform not working

W

WLMPilot

I have a userform with optionbutton3 that will make certain labels/textboxes
invisible when TRUE. If optionbutton3 is TRUE and then user clicks FINISHED,
the userform will HIDE.

The problem is when the userform is executed again and those
labels/textboxes are still invisible. I appreciate any input on how to fix
this!

Below are two macros. The first shows the userform. The second is the one
that should initialize the userform, making all visible:

Sub TimeCalc()
Dim TextBox1 As String
Dim TextBox2, TextBox3 As String
TimeCalcFm.Show
End Sub


Private Sub UserForm_Initialize()
Me.Label1.Caption = "Enter Date Worked"
Me.Label2.Visible = True
Me.Label3.Visible = True
Me.Label4.Visible = True
Me.TextBox2.Visible = True
Me.TextBox3.Visible = True
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.OptionButton1.Value = True
Me.TextBox1.SetFocus
End Sub

Thanks,
Les
 
J

JLGWhiz

What do you want to happen when you click option button 3? The code that is
displayed appears to be performing as written by your description. There is
nothing in the code to either hide or close the individual controls. If you
do not want them to appear when the userform is called, then you would have
to delete them from the initialize event and use the Add method to put them
 
J

Jim Thomlinson

Really there are 2 ways to go here depending on what you are wanting to do.

The initialize event is only triggered when the userform is first created.
Unhiding the userform does not trigger the event. Oddly enough the .show
method either creates an instance of the user form or it unhides the existing
instance. The Activate event fires when the userform is unhidden. So you
might be able to add code to the activate event to solve your problem. This
all assumes that you truely want to hide the existing instance of the form.
This is true when you want the end user to see the form exactly as they left
it when they last used it.

If you want the form to be reinitialized each time clearing out what the
user last entered then instead of hiding the form you should Unload (delete)
it. This completely gets rid of the form so that the next time .show is
called a new instance of the form will be created and the initialize event
will fire....
 
W

WLMPilot

The code that executes when Optionbutton3 is clicked works fine, which is why
I did not show it. The userform is designed to allow a user (me) to enter
and date,
time-in, and time-out from work. When ENTER is clicked, a macro will
calculate and place in a spreadsheet the appropriate time worked (in hours).
The three optionbuttons are 1-ENTER TIME 2-Correct Time (in entered in
error) and
3-Clear Time (in wrong date entered).

If optionbutton3 is TRUE, then the labels and textboxes used to obtain time
in and out become invisible because they are not necessary to clear time.

As stated, if optionbutton3 is TRUE and I click FINISHED (hide userform) and
later come back and click commandbutton to display userform and enter data,
the fields that were invisible are still invisible.

Hope this helps.
Les
 
W

WLMPilot

THANKS!!! Unload is what I needed.

Les


Jim Thomlinson said:
Really there are 2 ways to go here depending on what you are wanting to do.

The initialize event is only triggered when the userform is first created.
Unhiding the userform does not trigger the event. Oddly enough the .show
method either creates an instance of the user form or it unhides the existing
instance. The Activate event fires when the userform is unhidden. So you
might be able to add code to the activate event to solve your problem. This
all assumes that you truely want to hide the existing instance of the form.
This is true when you want the end user to see the form exactly as they left
it when they last used it.

If you want the form to be reinitialized each time clearing out what the
user last entered then instead of hiding the form you should Unload (delete)
it. This completely gets rid of the form so that the next time .show is
called a new instance of the form will be created and the initialize event
will fire....
 

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