title: VBA Access - alphabetically sort listbox
body: <p>I have two listboxes: listbox1 and listbox2. Listbox2 is a value list that is populated via user selection. I need to prevent duplicates from being entered into listbox2. My current solution checks the previous listbox record to see if it equals the current loop iteration- and if so, deletes the duplicate:</p>
  
  <pre><code>Set ctlSource = Me!listbox1
  For intCurrentRow = 0 To ctlSource.ListCount - 1
      If ctlSource.Selected(intCurrentRow) Then
          strItems = "'" &amp; ctlSource.Column(1, intCurrentRow) &amp; "'"
          Me!listbox2.AddItem (strItems)
      End If
  Next intCurrentRow
  
  Dim intItems As Integer
  Dim i As Integer
  
  
  
  'deletes  duplicates
  For i = 0 To Me.listbox2.ListCount - 1
          If Me!listbox2.ItemData(i) = Me!listbox2.ItemData(i - 1) Then
               Me!listbox2.RemoveItem (i)
          End If
  Next i
  </code></pre>
  
  <p>However, this requires that listbox2 be sorted. I want listbox2 to be sorted alphabetically anyway, so this method makes the most sense to me. I'm somewhat flabbergasted that I can't seem to find an existing listbox method or function that allows me to do this easily. I've perused through this forum and others, but haven't found a good solution. I guess R, Python, and SQL spoiled me. Any help would be appreciated...</p>