Hello,
I would like to see if it is possible to control the addition of Labels and text boxes based on a button click to my multipage object on my form. My initial thought was to use a case statement that would count the button clicks and add the labels and text boxes as needed. However, if I loop it of course I get all the labels and texts boxes at one time if I don't loop it I only get the one case for which the label and text box condition is true (resulting in only one Label and Textbox being created). Below is the code I am working with. Please let me know if there is a possible solution that I can add my these objects during runtime based on a button click.
The following is the image of my form and below that is the code. I feel like it could be as simple as properly declaring my variables correctly. I have thought of some work arounds but I would like to attempt to make this as concise as possible.
Thanks
Aholts
I would like to see if it is possible to control the addition of Labels and text boxes based on a button click to my multipage object on my form. My initial thought was to use a case statement that would count the button clicks and add the labels and text boxes as needed. However, if I loop it of course I get all the labels and texts boxes at one time if I don't loop it I only get the one case for which the label and text box condition is true (resulting in only one Label and Textbox being created). Below is the code I am working with. Please let me know if there is a possible solution that I can add my these objects during runtime based on a button click.
The following is the image of my form and below that is the code. I feel like it could be as simple as properly declaring my variables correctly. I have thought of some work arounds but I would like to attempt to make this as concise as possible.
Thanks
Aholts
Code:
Private Sub CmdBtn_AddNewGroup_Click()
Dim i As Integer
Dim BClicks As Integer
BClicks = 1
i = 1
For BClicks = 1 To 10
Select Case BClicks
Case 1
' Draw the labels
Set NewUnitGrpLbl = MultiPage1.Pages(1).Controls.Add("Forms.label.1")
With NewUnitGrpLbl
.Top = 118
.Left = 18
.Height = 18
.Name = "LBL_UnitGroup" & i + 1
.Caption = "Unit Group " & i + 1
End With
Set NewNumOfUnits = MultiPage1.Pages(1).Controls.Add("Forms.label.1")
With NewNumOfUnits
.Width = 114
.Top = 146
.Left = 24
.Height = 18
.Width = 114
.Name = "LBL_NumOfUnits" & i + 1
.Caption = "Number of Units in Group:"
End With
Set NewLeaseTerm = MultiPage1.Pages(1).Controls.Add("Forms.label.1", "LBL_LeaseTerm2", True)
With NewLeaseTerm
.Width = 102
.Top = 168
.Left = 24
.Height = 18
.Name = "LBL_LeaseTerm" & i + 1
.Caption = "Lease Term in Months:"
End With
Set NewMthlyRent = MultiPage1.Pages(1).Controls.Add("Forms.label.1", "LBL_MonthlyRent2", True)
With NewMthlyRent
.Width = 102
.Top = 190
.Left = 24
.Height = 18
.Name = "LBL_MonthlyRent" & i + 1
.Caption = "Monthly Rent"
End With
'Draw the Text Boxes
Set NewNumberOfUnitsInGroupTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewNumberOfUnitsInGroupTxt
.Name = "txt_NumOfUnitsInGroup" & i + 1
.Top = 141
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
Set NewLeaseTermTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewLeaseTermTxt
.Name = "txt_LeaseTerm" & i + 1
.Top = 163
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
Set NewMonthlyRentTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewMonthlyRentTxt
.Name = "txt_MthlyRent" & i + 1
.Top = 185
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
Case 2
' Draw the labels
Set NewUnitGrpLbl = MultiPage1.Pages(1).Controls.Add("Forms.label.1")
With NewUnitGrpLbl
.Top = 218
.Left = 18
.Height = 18
.Name = "LBL_UnitGroup" & i + 1
.Caption = "Unit Group " & i + 1
End With
Set NewNumOfUnits = MultiPage1.Pages(1).Controls.Add("Forms.label.1")
With NewNumOfUnits
.Width = 114
.Top = 246
.Left = 24
.Height = 18
.Width = 114
.Name = "LBL_NumOfUnits" & i + 1
.Caption = "Number of Units in Group:"
End With
Set NewLeaseTerm = MultiPage1.Pages(1).Controls.Add("Forms.label.1", "LBL_LeaseTerm2", True)
With NewLeaseTerm
.Width = 102
.Top = 268
.Left = 24
.Height = 18
.Name = "LBL_LeaseTerm" & i + 1
.Caption = "Lease Term in Months:"
End With
Set NewMthlyRent = MultiPage1.Pages(1).Controls.Add("Forms.label.1", "LBL_MonthlyRent2", True)
With NewMthlyRent
.Width = 102
.Top = 290
.Left = 24
.Height = 18
.Name = "LBL_MonthlyRent" & i + 1
.Caption = "Monthly Rent"
End With
'Draw the Text Boxes
Set NewNumberOfUnitsInGroupTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewNumberOfUnitsInGroupTxt
.Name = "txt_NumOfUnitsInGroup" & i + 1
.Top = 241
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
Set NewLeaseTermTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewLeaseTermTxt
.Name = "txt_LeaseTerm" & i + 1
.Top = 263
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
Set NewMonthlyRentTxt = MultiPage1.Pages(1).Controls.Add("Forms.textbox.1")
With NewMonthlyRentTxt
.Name = "txt_MthlyRent" & i + 1
.Top = 285
.Left = 156
.MultiLine = False
.EnterKeyBehavior = True
.Height = 18
End With
End Select
'BClicks = BClicks + 1
Next BClicks
i = i + 1
End Sub
Last edited: