Search code examples
exceluserformvba

Display string of text in textbox based on the multiple checkbox in userform


I created a simple userform with 4 checkboxes and 1 textbox.

enter image description here

I want to be able to display sentences based on the checkbox that is clicked. if checkboxSwimming pool is check, i want to display this string: The caller mentioned about Swimming Pool.

if checkbox swimmingpool and checkbox balcony is check, i want to display this string.

The caller mentioned about Swimming Pool. The caller mentioned about Balcony.

and son on.

here's my code so far:

Private Sub CommandButton1_Click()

'If chkPool.Value = True Then
'txtComment.Text = "The caller asked about Swimming Pool."

'ElseIf chkBalcony.Value = True Then
'txtComment.Text = "The caller asked about Balcony and Patio."

'End If

Select Case test_test

Case chkPool.Value = True
txtComment.Text = "The caller asked about Swimming Pool."


Case chkPool.Value = True & chkBalcony.Value = True
txtComment.Text = "The caller asked about Swimming Pool."
txtComment.Text = "The caller asked about balcony."


End Select




End Sub

Solution

  • Is this what you are looking for?

    Private Sub CommandButton1_Click()
    
    txtComment.Text = ""
    
    If chkPool.Value = True Then
        txtComment.Text = txtComment.Text & "The caller asked about Swimming Pool." & Chr(10)
    End If
    
    If chkBalcony.Value = True Then
        txtComment.Text = txtComment.Text & "The caller asked about Balcony and Patio." & Chr(10)
    End If
    
    '... add more IF clauses for the other check boxes here...
    
    
    End Sub
    

    Just make sure that the text box is MultiLine = True.