View Single Post
 
Old 04-01-2022, 03:19 AM
grNadpa grNadpa is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Mar 2022
Posts: 46
grNadpa is on a distinguished road
Default

By restating my question (below), I blundered into my answer.

Assume a combox containing "Adam", Beverly" and "Charles". When the client selects one of those, I want to capture the Listindex. If, instead, the client types in something else, I want to capture what the client typed (e.g. "Alfred"). Is there a way in VBA to do that? Preferably without requiring another control.

Code:
Private Sub CommandButton1_Click()
    With ComboBox1
        .AddItem "Adam"
        .AddItem "Beverly"
        .AddItem "Charles"
    End With
End Sub
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With ComboBox1
        MsgBox "Listindex: " & .ListIndex
        MsgBox "Name: " & .Text
    End With
End Sub
That is, thought I had tried _Exit event before. Whatever I coded didn't work at the time so thought it was the strategy. Apparently it was just the coding.

Last edited by grNadpa; 04-01-2022 at 05:35 AM. Reason: Solved
Reply With Quote