I am having trouble trying to make an object visible in one useform when the check box is checked in another userform. (e.g. Getting a label to be displayed in Userform 2 when the checkbox is checked in Userform 1)
Is there a way to solve this issue?
CodePudding user response:
Just now I make a test.
Create two user forms : uf1 and uf2.
I make "Show Modal" to false on each user form property.
In uf1 I put two checkbox : cb1 and cb2.
In uf2 I put one label : Label1
Then I open both of the user forms.
Tick the cb1 in uf1, the Label1 shows in uf2
Untick the cb1, The Label1 is hidden in uf2.
If that's what you mean, the code is like this :
Sub in uf1
Private Sub cb1_Click()
If cb1 = True Then uf2.Label1.Visible = True Else uf2.Label1.Visible = False
End Sub
Sub in uf2
Private Sub UserForm_Initialize()
Label1.Visible = False
End Sub
Please note that the code in uf1 doesn't do error checking, for example : if uf2 is not exist (not showing) then .....
CodePudding user response:
Objects in Another UserForm
- In both user forms, manually set the
ShowModal
property toFalse
.
UserForm1
Option Explicit
Private Sub CheckBox1_Click()
ShowLabel
End Sub
Private Sub UserForm_Initialize()
If UserForm2.Visible Then CheckCheckBox
End Sub
UserForm2
Option Explicit
Private Sub UserForm_Initialize()
ShowLabel
End Sub
Module1
Option Explicit
Sub CheckCheckBox()
UserForm1.CheckBox1 = UserForm2.Label1.Visible
End Sub
Sub ShowLabel()
UserForm2.Label1.Visible = UserForm1.CheckBox1
End Sub