question regarding Visible Propery

B

Basta1980

Hi,

See code below. When I open workbook, click the assigned button userform1
appears & although my username is not dresses frame4 and commandbutton2 are
shown. When I close userform1 and then reopen userform1 through the
aforementioned button frame4 and commandbutton2 are hidden (like it should).
Can anyone help me with this?



Sub Uncancel_sim()

UserForm1.Show
If Application.UserName = "dresses" Then
UserForm1.CommandButton2.Visible = False
UserForm1.Frame4.Visible = False
Else
UserForm1.CommandButton2.Visible = True
UserForm1.Frame4.Visible = True
End If

End Sub

Regards,

Basta1980
 
R

Ryan H

I would try reversing your code. Load the userform first, set the control
properties, then show the userform.

Sub Uncancel_sim()

Load Userform1

If Application.UserName = "dresses" Then
Userform1.CommandButton2.Visible = False
Userform1.Frame4.Visible = False
Else
Userform1.CommandButton2.Visible = True
Userform1.Frame4.Visible = True
End If

Userform1.Show

End Sub

Hope this helps! If so, let me know click "YES" below.
 
R

Ryan H

Forgot to tell you this. If you step thru your code (using F8 button) you
will see your code stops at Userform1.Show. Because it stops at .Show, your
If...Then statement isn't executed until you close the userform. What is
happening is when you close your userform the remainder of your code runs and
the userform remains loaded into memory. Thats why you see your code running
correctly the second time you open the userform.
 

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