Results 1 to 3 of 3

Thread: Manipulating multi line TB in UserForm - add and remove specific lines

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Jun 2016
    Posts
    53
    Location

    Manipulating multi line TB in UserForm - add and remove specific lines

    Hello,

    i am currently working on a userform which allows the user to add specific selections (text from listboxes) to a multiline textbox.
    Now i am trying to give the user the option to remove certain lines of text from this textbox in case that a false selection has been added to the textbox.

    This is what i currently have:

    Populating the listboxes: (don't mind the variables, i just add this here, so that you can see where content for the multiline textbox is coming from)

        
    Private Sub UserForm_Initialize()
    
        With ListBox1
            .AddItem "Gehäusedichtung"
            .AddItem "O-Ring Gehäusedichtung"
            .AddItem "O-Ring Stoßfangdichtung"
            .AddItem "Ventileinsatzdichtung"
            .AddItem "Filterkäfigdichtung"
            .AddItem "O-Ring Filterkäfigdichtung"
            .AddItem "Überdruck-Ventiltellerdichtung"
            .AddItem "Unterdruck-Ventiltellerdichtung"
            .AddItem "Ablassschraubendichtung"
        End With
    
        With ListBox2
            .AddItem "Flammensicherung"
            .AddItem "Kondensatablaufsicherung"
            .AddItem "Flammenfilterscheibe (L)"
            .AddItem "Flammenfilterscheibe (R)"
            .AddItem "Flammenfilterscheibe (G)"
        End With
    
        With ListBox3
            .AddItem "Überdruck-Ventilteller"
            .AddItem "Unterdruck-Ventilteller"
        End With
        
        If ActiveDocument.FormFields("TypAdd1").Range = "/" Then
            appNameTBContent = ActiveDocument.FormFields("Hersteller").Range  & "®" & " " & ActiveDocument.FormFields("Typ").Range &  "-" & ActiveDocument.FormFields("TypAdd2").Range
        Else
            appNameTBContent = ActiveDocument.FormFields("Hersteller").Range  & "®" & " " & ActiveDocument.FormFields("Typ").Range &  "-" & ActiveDocument.FormFields("TypAdd1").Range & "-" &  ActiveDocument.FormFields("TypAdd2").Range
        End If
        appNameTB.Text = appNameTBContent
    
    End Sub
    I have two CommandButtons in the UserForm. One for adding a selected Listbox item to the Textbox (cmdAddLB1) and one for removing a selected Listbox item from the Textbox (cmdRemoveLB1).
    Selecting an item from the ListBox and adding this selection to the textbox by clicking the cmdAddLB1 CommandButton works just fine.
    But i am a little bit confused on how i would go about removing selected Listbox items from the Textbox when the cmdRemoveLB1 CommandButton is clicked.

    To add items to the Textbox i wrote the following code:

    Private Sub cmdAddLB1_Click()
    Dim ListBoxItem As Variant
    Dim gasketPreview0, gasketPreview1, gasketPreview2, gasketPreview3,  gasketPreview4, gasketPreview5, gasketPreview6, gasketPreview7,  gasketPreview8 As String
    
    'Just comments to see the content of each ListBox index
    'ListBox Index 0 = "Gehäusedichtung"
    'ListBox Index 1 = "O-Ring Gehäusedichtung"
    'ListBox Index 2 = "O-Ring Stoßfangdichtung"
    'ListBox Index 3 = "Ventileinsatzdichtung"
    'ListBox Index 4 = "Filterkäfigdichtung"
    'ListBox Index 5 = "O-Ring Filterkäfigdichtung"
    'ListBox Index 6 = "Überdruck-Ventiltellerdichtung"
    'ListBox Index 7 = "Unterdruck-Ventiltellerdichtung"
    'ListBox Index 8 = "Ablassschraubendichtung"
        
        Select Case ListBoxItem
        Case ListBox1.Value = 0
        If SpinButtonLB1.Value = 0 Then
            gasketPreview0 = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
            If contentPreview.Text = "" Then
            contentPreview.Text = gasketPreview0
            ElseIf Not contentPreview.Text = "" Then
            contentPreview.Text = contentPreview.Text & vbCrLf & gasketPreview0
            End If
        ElseIf SpinButtonLB1.Value > 0 Then
            gasketPreview0 = "• " & counter1.Text & "x " &  appNameTB.Text & " " & ActiveDocument.FormFields("GDTNG").Range  & " " & ListBox1.Value & " erneuert."
            If contentPreview.Text = "" Then
            contentPreview.Text = gasketPreview0
            ElseIf Not contentPreview.Text = "" Then
            contentPreview.Text = contentPreview.Text & vbCrLf & gasketPreview0
            End If
        End If
    
        Case ListBox1.Value = 1
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 2
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 3
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 4
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 5
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("GDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 6
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("PVDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 7
            contentPreview.Text = "• " & appNameTB.Text & " " &  ActiveDocument.FormFields("VVDTNG").Range & " " & ListBox1.Value  & " erneuert."
        Case ListBox1.Value = 8
            contentPreview.Text = "• " & appNameTB.Text & " " & ListBox1.Value & " erneuert."
        Case Else
            MsgBox "Es wurde nichts ausgewählt!" & vbCr & _
            "Wähle einen Listeneintrag um diesen zu übertragen!"
        End Select
    End Sub

    Private Sub cmdRemoveLB1_Click()
    ' No working code so far =(
    End Sub
    I dont really know how the cmdRemoveLB1_Click() procedure needs to be set up in order for this to work.
    Is this only possible with an array?
    Declaring the contentPreview TextBox as an array,
    Clicking cmdAddLB1 would add the selected ListBox item to that array.
    Clicking cmdRemoveLB1 would remove the selected ListBox from that array?

    I have attached a screenshot of the UserForm to illustrate my problem.
    I also attached a simplified testDocument to take a look at if someone is interested to help.

    Attachment 25289


    If someone could help me out here it would be much appreciated.

    best regards

    Manuel
    Attached Images Attached Images
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •