Consulting

Results 1 to 19 of 19

Thread: Multiple Selection From ListBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor
    Joined
    Aug 2020
    Location
    Hampshire
    Posts
    402
    Location

    Multiple Selection From ListBox

    Moving on from the ComboBox method, trying to enable selection of more than one from a ListBox is throwing up

    Run-Time Error '94': Invalid use of null

    Private Sub UserForm_initialize()
    
    Dim myArray     As Variant
        myArray = Split("- Select One Or More -|Requires further investigation|Urgent review|" _
                & "Manageable risk|For Noting Only", "|")
        'Use List method to populate listbox
        ListBox1.List = myArray
        ListBox1.ListIndex = 0
        
    'Redefine list for reason for threat level
        'Select threat level
        'Create list of grades for threat
        myArray = Split("- Select -|High|Medium|Low", "|")
        'Use List method to populate listbox
        ComboBox2.List = myArray
        ComboBox2.ListIndex = 0
        'Use List method to populate listbox
        ComboBox3.List = myArray
        ComboBox3.ListIndex = 0
        'Use List method to populate listbox
        ComboBox4.List = myArray
        ComboBox4.ListIndex = 0
        'Use List method to populate listbox
        ComboBox5.List = myArray
        ComboBox5.ListIndex = 0 
    
     lbl_Exit:
        Exit Sub
    End Sub
    
    
    Private Sub ListBox1_Change()
        If ListBox1.ListIndex > 0 Then
            TextBox2.Text = ListBox1.Value
        End If
        Select Case ListBox1.Value
            Case "Requires further investigation":
                TextBox2.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In rhoncus, lorem et fringilla dictum, orci orci posuere lacus, ut auctor libero neque non purus. Fusce a commodo ligula."
            Case "Urgent review":
                TextBox2.Text = "Proin sed nisl enim. Cras in nisl tempus, scelerisque mi id, vulputate arcu. Duis nec mi ac lorem pretium semper."
            Case "Manageable risk":
                TextBox2.Text = "Fusce eu nisi sollicitudin, pharetra nibh sed, vestibulum neque. Praesent a auctor turpis. Mauris posuere vitae justo ac mollis."
            Case "For Noting Only":
                TextBox2.Text = "Sed eu eros ipsum. Ut posuere id magna eu sollicitudin. Nunc suscipit tempor egestas. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos."
            Case Else
                TextBox2.Text = ""
        End Select
        
    lbl_Exit:
        Exit Sub
    End Sub
    I've highlighted where it falls over.

    I want to allow the user to be able to select none, one or more from the list (I intend to add more options to the list once this is working).

    As an aside, what is the maximum amount of characters I could use for TextBox2.Text ?

    Thanks!
    Last edited by HTSCF Fareha; 08-23-2020 at 03:06 AM.

Posting Permissions

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