harveya915
Board Regular
- Joined
- Sep 4, 2015
- Messages
- 141
I have a UserForm with TextBoxes, Labels, CommandButtons, and a Checkbox.
I need that for when the checkbox value is true for a new label and textbox to appear. I have this part figured out.
However what I need now is for when I uncheck the the checkbox for those new label and textbox to go away.
The checkbox value is false by default. So when I first open the UserForm, the checkbox is not selected (value=false). I would like for my code to be able to where if I select (true) the extra label and checkbox appear, but if I change my mind I unselect (false) the checkbox and they dissapear, but if I check again they appear, and so on and so forth.
Oh and when the new label and textbox appears, certain commandbuttons, labels, and textboxes move to make way for the new ones. and when checkbox is unselected they go back to their original spot.
This is what I have so far:
I don't have much experience with this. Everything has been by research here and there. Much thanks!
I need that for when the checkbox value is true for a new label and textbox to appear. I have this part figured out.
However what I need now is for when I uncheck the the checkbox for those new label and textbox to go away.
The checkbox value is false by default. So when I first open the UserForm, the checkbox is not selected (value=false). I would like for my code to be able to where if I select (true) the extra label and checkbox appear, but if I change my mind I unselect (false) the checkbox and they dissapear, but if I check again they appear, and so on and so forth.
Oh and when the new label and textbox appears, certain commandbuttons, labels, and textboxes move to make way for the new ones. and when checkbox is unselected they go back to their original spot.
This is what I have so far:
VBA Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
'this is to shift down and make way for new label and textbox
CommandButton1.Top = 312
CommandButton1.Left = 144
CommandButton2.Top = 312
CommandButton2.Left = 252
Label7.Top = 354
Label7.Left = 30
TextBox7.Top = 366
TextBox7.Left = 30
CommandButton3.Top = 498
CommandButton3.Left = 198
'this renames some labels
Label3.Caption = "Amount of Payment Increase"
Label4.Caption = "New Payment Amount"
Label5.Caption = "First Additional Payment Due"
'this adds the new textbox and label to a certain position
Dim ctlTxt As MSForms.Control
Dim ctlLbl As MSForms.Control
Set ctlTxt = Me.Controls.Add("Forms.TextBox.1")
ctlTxt.Top = 276
ctlTxt.Left = 222
ctlTxt.Height = 24
ctlTxt.Width = 120
ctlTxt.BorderStyle = 0
ctlTxt.SpecialEffect = 0
ctlTxt.BackColor = &H80000018
ctlTxt.Value = ""
Set ctlLbl = Me.Controls.Add("Forms.Label.1")
ctlLbl.Top = 276
ctlLbl.Left = 96
ctlLbl.Height = 24
ctlLbl.Width = 120
ctlLbl.Font.Size = 10
ctlLbl.Caption = "First Additional Payment Due Date"
End If
If CheckBox1.Value = False Then
'this puts them back to their original place
CommandButton1.Top = 270
CommandButton1.Left = 144
CommandButton2.Top = 270
CommandButton2.Left = 252
Label7.Top = 318
Label7.Left = 30
TextBox7.Top = 330
TextBox7.Left = 30
CommandButton3.Top = 462
CommandButton3.Left = 198
'puts original caption back on renamed labels
Label3.Caption = "# of Monthly Payments"
Label4.Caption = "Amount of Payment"
Label5.Caption = "First Due Date"
End If
End Sub
I don't have much experience with this. Everything has been by research here and there. Much thanks!