Copy Texts from Checkbox and Combo Box to Textbox

  • Hello everyone!

    I am just new here in the forum. Thank in advance for any help! Bare with me as I am fairly new to programming.


    So I have a UserForm1 that contains the following:

    • Checkbox

    • Combobox

    • TextBox


    What I want to do:

    First of all, I want the choices from the boxes (check and combo) to be shown in TextBox1 when checked/selected.

    Second, I want to format the text's that is shown.


    For instance, I have a combobox showing 3 options: Name, Country, Address (sample only) If I choose "Name", I want to show a 2-liner text instead of the word "Name".

    Also, I want the text to appear on TextBox1 as a lists with bullets.

    This is only for some options; for others, I only want the same texts in the boxes to be shown in TextBox1.


    Thank you!

  • PS.


    I am not going to use a Command Button to generate the text on TextBox1. As much as possible, I want the text to show as soon as the checkbox was checked or an item from a ComboBox is selected. I also want the text deleted once option has been unchecked or unselected.

  • You don't give much detail to provide an answer. Also, in this case you should provide an example of your workbook, you shouldn't expect someone to re-create it.


    This is what I think that you want

  • Hello again,


    Thank you again royUK for your work. I have seen it and I have attached my sample worksheet here for proper reference.


    Here's what I am trying to accomplish.

    1. I am hoping the "caption" of the Checkbox be displayed to textbox.

    2. I am hoping the "label", which is "Received" and "Required", be displayed on the textbox as well once I choose an option via Checkbox.

    3. The texts displayed on the textbox must be displayed on how the options are displayed on the UserForm. For instance, under Received, Name comes as first, then address, etc.

    4. On the ComboBox, there are 2 options. I want to display these options, once selected, on the textbox and add 2 more lines of text. FOr instance, the 1st option is Address Required. I want to show the following texts:


    Address Required

    • Bank Statement

    • Utility Bill


    5. There should be a copy and clear button, but I already have that figured out, at least.


    I know this is all too much, I appreciate all your help guys.

  • Hi Chester,


    This is one approach, I have only written some of it but hopefully you can modify to suit.


    Note that you had an error in your initialize code - I think it was referring to combobox 5

    You need to change textbox1 to enable multline, this option is in the TextBox1 properties window.


    Let me know if it is on the right track.

  • That is nothing like what you asked originally. Ask your questions correctly in future the first time!!


    Your code errors before the userform even initialises.


    I see no reason to have two columns of CheckBoxes.


    I would use a ListBox and only one set of CheckBoxes seems to be required


    What happens with the second selection in the combobx?


    Where do you want to copy to?

  • royUK and Justin Doward again, I appreciate all your help. I think both your work already answers my question here.


    I apologize for all the run-around. I will do better next time. It is my first time posting.

    I'll post a better question, with better and complete format, next time!


    Cheers!

  • Hey royUK .


    I did check your work first.


    This UserForm is supposed to be a simple user form in creating a "Note Generator" for work. I thought having this would give me an easier time at work.


    I have 2 columns of check boxes because I want 1 column for Documents Received and 1 column for Documents Needed (To be requested). This way, I would have a sort of checklist of what I need to ask from clients. So, in a sense, it is very important for me to have 2 columns.


    For the combo box, I admit I am unsure if this is right "function" to use here. I am not gonna do multiple selection, I will only choose one from the list. As I stated above, upon selecting an option from the box, I want that same text be displayed on textboxt1 along with another 2-liner.


    For the copy, I only want it on my clipboard and I'll post it somewhere in my system (outside excel) like Notepad or something. The below is my code for copying the text. Correct me if I am wrong.


    Code
    1. ' ' Copy Text from TextBox
    2. Private Sub CommandButton1_Click()
    3. With New MSForms.DataObject
    4. .SetText TextBox1.Text
    5. .PutInClipboard
    6. End With
    7. End Sub

    Since I am a newbie in this. I thought the code of Justin Doward is "easier" for me to understand. Though, I have only tested the checkboxes for now. With that, I want to add another query here. I have this code so far:


    My problem here is, after un-ticking check box 2, it is not "removed" on the textbox. It stays on the textbox and when I click again on the same checkbox, the same texts was doubled. I added the below code on Checkbox2, but it didn't do any better.

    Code
    1. Me.TextBox1.Text = vbNullString
  • My code checks what is received or not and seems a simpler approach. Try it and you will see that it says received or required


    Also, my clear button resets everything in an efficient way.


    I can add code to write to the ClipBoard when it's finished or probably simpler to export to a text file.

  • The initialise error is caused here

    Code
    1. With UserForm5.ComboBox1

    You can simply remove UserForm5 or use


    Code
    1. With Me.ComboBox1

    Oh yeah, for the initialize error, I simply copy the code from my original workbook, that's why it has the UserForm5. I thought I saved it before posting it here. My bad. I'll replace it with yours.

  • If you use this approach you pretty much have to build the entire text each time, clear the box using the me.textbox1.text = vbnullstring and then add a line to check checkbox1, 2 and 3 in order and build the text as required. You will need to do the same for the combobox.

    bare with me on this one, as I try to comprehend it. lol

    When you gave me the below code, does that mean I literally just paste it under Checkbox1_Click? and, just replace Me.CheckBox4.Value to the other check boxes?


    Code
    1. Private Sub CheckBox1_Click()
    2. Me.TextBox1.Text = vbNullString
    3. If Me.CheckBox1.Value = True Then
    4. Me.TextBox1 = Label1.Caption & vbNewLine & CheckBox1.Caption
    5. If Me.CheckBox4.Value = True Then Me.TextBox1.Text = Me.TextBox1.Text & vbNewLine & Me.CheckBox4.Caption
    6. If Me.CheckBox5.Value = True Then Me.TextBox1.Text = Me.TextBox1.Text & vbNewLine & Me.CheckBox5.Caption
    7. End If
    8. End Sub
  • This example uses a TextBox


    I'm still not sure what happens if the second selection in the combobox is selected.

  • This example uses a TextBox


    I'm still not sure what happens if the second selection in the combobox is selected.

    For the second option in the combox box, technically, they function the same as the 1st option. For instance,


    Selecting the 1st option displays:

    • Address Required

    • Need POA

    • Need Bank Statement


    Selecting the 2nd option displays:

    • Country Required

    • Need Passport

    • Need POI



    Also, from your work, is there any chance it would appear just like how it appears on the above example?