Hello!
I'm quite new to VBA and trying to write a Module Sub that creates a dynamical UserForm and calls it.
In detail, I'm trying to do the following:
In my Sub "Note" there is an array called “wahlpflicht” that contains names which should be displayed in my UserForm (I tried to put them in as labels).
Each name should have two checkboxes and a TextBox at its side.
After filling out the checkboxes and the textbox the user's input should be confirmed by clicking a button (button1).
After the confirmation, I want to use the given input per each Wahlpflicht-name (checkbox 1 or 2 checked? content of the textbox?) forward in my Sub Note.
I already managed to create the UserForm with the desired names and checkboxes/textboxes. But now I don't know how to force my Sub "Note" to continue only after clicking the button1.
Could anyone please help?
My code so far is the following:
Module1:
UserForm1:
I'm quite new to VBA and trying to write a Module Sub that creates a dynamical UserForm and calls it.
In detail, I'm trying to do the following:
In my Sub "Note" there is an array called “wahlpflicht” that contains names which should be displayed in my UserForm (I tried to put them in as labels).
Each name should have two checkboxes and a TextBox at its side.
After filling out the checkboxes and the textbox the user's input should be confirmed by clicking a button (button1).
After the confirmation, I want to use the given input per each Wahlpflicht-name (checkbox 1 or 2 checked? content of the textbox?) forward in my Sub Note.
I already managed to create the UserForm with the desired names and checkboxes/textboxes. But now I don't know how to force my Sub "Note" to continue only after clicking the button1.
Could anyone please help?
My code so far is the following:
Module1:
VBA Code:
Sub Note()
Dim wahlpflicht() As String, size2 As Integer
...
Call UserForm1.addLabel(CInt(n), wahlpflicht)
UserForm1:
VBA Code:
Sub addLabel(n As Integer, ByRef names() As String)
UserForm1.Show vbModeless
Dim theLabel As Object
Dim theInput As Control
Dim edtBox_n As Control
Dim labelCounter As Long
With Me
For labelCounter = 0 To n
Set theLabel = UserForm1.Controls.Add("Forms.Label.1", "Label" & labelCounter, True)
With theLabel
.Caption = names(labelCounter)
.Width = 500
.Height = 30
.Left = 10
.Top = 50 * (labelCounter + 1)
End With
Set Cbx = UserForm1.Controls.Add("Forms.CheckBox.1", "Checkbox" & labelCounter, True)
With Cbx
.Top = 50 * (labelCounter + 1)
.Left = 200
.Caption = "Check"
End With
Set Cbx2 = UserForm1.Controls.Add("Forms.CheckBox.1", " ", True)
With Cbx2
.Name = "CB_" & labelCounter
.Top = 50 * (labelCounter + 1)
.Left = 300
.Caption = "Check"
End With
Set theInput = UserForm1.Controls.Add("Forms.TextBox.1", "theInput", True)
With theInput
.Top = 50 * (labelCounter + 1)
.Left = 400
'.MultiLine = True
.EnterKeyBehavior = True
.Height = 30
.Width = 80
End With
Next
End With
With UserForm1
If .Tag = "OK" Then
For Each myControl In UserForm1.Controls
If (TypeName(myControl) = "CheckBox") Then
If (myControl.Value = True) Then
MsgBox (myControl.Name)
End If
End If
Next
End If
End With
'Unload UserForm1
End Sub