i have a userform which has 2 tabs and each has 2 frames where in each frame has 6 to 7 checkboxes. I have a lot of array values for all the checkboxes. Now the issue is when i click checkbox1 the corresponding array value should be called and inserted in textbox. so on and so forth for all checkboxes.
When i assign a string value to the checkbox on the first click itself i am getting the string in the text box, but with the array values it happens from the second click. I am not able to understand why this is happening.I have recently started vba and would appreciate all the help.
thanks a lot P.s
This is the code i have tried till now
Public strArrPositiveNote(3) as string
Sub DisplayManager() Dim ctrl As MSForms.Control, txt As String
txt = vbNullString
MyForm.TextBox2.Value = txt
For Each ctrl In MyForm.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.Value Then
txt = txt & GetMessage(ctrl.Name) & vbCrLf
End If
End If
Next ctrl
'MyForm.TextBox2.Value = txt
strArrPositiveNote(0)=”First note”
strArrPositiveNote(1)=”Second note”
End sub
Function GetMessage(cbName As String) As String
Dim str As String
If cbName = "CheckBox1" Then
Str= “first note”--- works for this
str = strArrPositiveNote(6)
ElseIf cbName = "CheckBox2" Then
str = strArrPositiveNote(2)
' str = "two"
ElseIf cbName = "CheckBox3" Then
str = strArrPositiveNote(0)
ElseIf cbName = "CheckBox4" Then
str = strArrPositiveNote(5)
ElseIf cbName = "CheckBox5" Then
str = strArrPositiveNote(1)
ElseIf cbName = "CheckBox6" Then
str = strArrPositiveNote(3)
ElseIf cbName = "CheckBox7" Then
str = strArrPositiveNote(4)
End If
GetMessage = str End Function
Aucun commentaire:
Enregistrer un commentaire