Forum Discussion

S_Leonardo's avatar
S_Leonardo
Occasional Contributor
9 years ago
Solved

Problem showing a listbox with selected items using .ShowModal

Hi, I got some difficulties trying to load a listbox with some selected items using .ShowModal   Example of my code(VBScript):   With UserForms.MyForm.ListBoxABC   .Add("Test_01")   .Add("Test...
  • Ryan_Moran's avatar
    Ryan_Moran
    9 years ago

    The form is not yet shown when you are setting the selected property of the item and therefore cannot be set.

    You need to add an event handler for the OnShow event of the userform and set the selected property after the form is shown.

     

    With UserForms.MyForm.ListBoxABC
      .Add("Test_01")
      .Add("Test_02")
      .Add("Test_03")
    End With
    '
    
    UserForms.MyForm.ShowModal 
    
    Sub OnShow_Handler(Sender)
        'Set this handler under the events section for the form in the designer
        UserForms.MyForm.ListBoxABC.Selected( 0) = True
    End Sub

    Reference event handling here.