Hi chester, as you outlined pretty much just copy the code to each of the check boxes and it will redraw the text each time. There are probably more elegant ways to achieve it, but brute force will do the job as well. I have not seen how Roy is approaching it but if you can adapt his method it is probably preferable (i.e. more elegant :))
Copy Texts from Checkbox and Combo Box to Textbox
-
chester1993 -
July 19, 2020 at 3:42 AM -
Thread is marked as Resolved.
-
-
-
Replace the code in my last example with this
Code
Display MoreDim iX As Integer Private Sub ComboBox1_Change() Dim str As String Dim iY As Integer With Me.TextBox1 .Value = Empty If Me.ComboBox1.ListIndex < 0 Then Exit Sub For iX = 1 To 3 If Me("chk" & iX) = True Then iY = 1 Else: iY = 2 End If Me.TextBox1.Value = Me.TextBox1.Value & Chr(149) & " " & Me("chk" & iX).Caption & " " & Choose(iY, "Received", "Required") & vbNewLine Next iX If Me.ComboBox1.ListIndex = 0 Then With Me.TextBox1 .Value = .Value & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Bank Statement required" & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Utility Bill required" End With Else With Me.TextBox1 .Value = .Value & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Passport required" & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "POI required" End With End If End With End Sub Private Sub CommandButton1_Click() Reset End Sub Sub Reset() ''///reset controls Me.ComboBox1.ListIndex = -1 Me.TextBox1.Value = Empty For iX = 1 To 3 Me("chk" & iX) = False Next iX End Sub
-
Replace the code in my last example with this
Code
Display MoreDim iX As Integer Private Sub ComboBox1_Change() Dim str As String Dim iY As Integer With Me.TextBox1 .Value = Empty If Me.ComboBox1.ListIndex < 0 Then Exit Sub For iX = 1 To 3 If Me("chk" & iX) = True Then iY = 1 Else: iY = 2 End If Me.TextBox1.Value = Me.TextBox1.Value & Chr(149) & " " & Me("chk" & iX).Caption & " " & Choose(iY, "Received", "Required") & vbNewLine Next iX If Me.ComboBox1.ListIndex = 0 Then With Me.TextBox1 .Value = .Value & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Bank Statement required" & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Utility Bill required" End With Else With Me.TextBox1 .Value = .Value & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "Passport required" & vbNewLine .Value = .Value & Chr(149) & " " & Me.ComboBox1.Value & " " & "POI required" End With End If End With End Sub Private Sub CommandButton1_Click() Reset End Sub Sub Reset() ''///reset controls Me.ComboBox1.ListIndex = -1 Me.TextBox1.Value = Empty For iX = 1 To 3 Me("chk" & iX) = False Next iX End Sub
Thank you, royUK and Justin Doward .
I'll try this new code and let you guys know.
-
Your copy code doesn't seem to work, I think due to recent changes with the ClipBoard.
I've added code to the copy button to write to a Text file.
-
Hey royUK . On the reset button you created on this UserForm, I am having a variable not defined error.
My code here is, and I modified yours:
CodeSub Reset() ''///reset all controls using Function Me.ComboBox1.ListIndex = -1 Me.ComboBox2.ListIndex = -1 Me.TextBox1.Value = Empty Me.TextBox2.Value = Empty For iX = 1 To 19 Me("CheckBox" & iX) = False Next iX End Sub
As you can see, I now have 2 ComboBoxes, 2 TextBoxes and 19 CheckBoxes I need to clear.
I am using the same reset code for my other userform with 15 checkboxes and is working fine.
Name of the checkboxes are default only that's why I have "CheckBox" there instead of "chk" from the one you initially shared.
What do you think is making that error here?
-
-
I think I found another way to do it. Sharing it here for future use. Works fine.
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!