Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check the type of lstPorts2:</p> <pre><code>Debug.Print "TypeName(lstPorts2): " &amp; TypeName(lstPorts2) </code></pre> <p>Your description sounds like lstPorts2 may actually be an Access listbox rather than an MSForms.ListBox ... and those are different object types. For example, an Access listbox doesn't have the <em>Clear</em> method you're using in your sort routine.</p> <p>Perhaps you could convert to an Access listbox and have SortListBox use the <em>RemoveItem</em> method for all the listbox members as a substitute for <em>Clear</em>. </p> <p><strong>Edit</strong>: I'm unsure what TypeName would say for a MSForms.ListBox, so I may be off base here. Still I would open the form module, type <strong>Me.lstPorts2.</strong> and see if IntelliSense offers <em>Clear</em> as one of the methods/properties. </p> <p>I'm on shaky ground with MSForms. Can you make lstPorts2 an Access listbox instead? If so, I think revising SortListBox to this could work:</p> <pre><code>Public Sub SortListBox(ByRef oLb As ListBox) Dim vaItems As Variant Dim i As Long, j As Long Dim vTemp As Variant 'Put the items in a variant array ' vaItems = Split(oLb.RowSource, ";") For i = LBound(vaItems, 1) To UBound(vaItems, 1) - 1 For j = i + 1 To UBound(vaItems, 1) If vaItems(i, 0) &gt; vaItems(j, 0) Then vTemp = vaItems(i, 0) vaItems(i, 0) = vaItems(j, 0) vaItems(j, 0) = vTemp End If Next j Next i 'Clear the listbox ' For i = (oLb.ListCount - 1) To 0 Step -1 oLb.RemoveItem (i) Next i 'Add the sorted array back to the listbox ' For i = LBound(vaItems, 1) To UBound(vaItems, 1) oLb.AddItem vaItems(i, 0) Next i End Sub </code></pre> <p>Actually, clearing an Access listbox whose RowSourceType is "Value List" could be simpler:</p> <pre><code>oLb.RowSource = "" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload