Add code to sort added combo box items alphebetically

P

Pamela

How can I have the items that are added to my combo box add to the list in
alphebetical order? I currently have it coded to be able to add item on
NotInList event but the item is added to the end of the list. Here is the
code I have now:

Private Sub cboInsuranceCoID_NotInList(NewData As String, Response As Integer)
If MsgBox(NewData & " is not in the list." & vbCrLf & "Would you like to
add" & NewData & "?", vbQuestion + _
vbYesNo + vbDefaultButton2, "Not Found") = vbYes Then

Me.cboInsuranceCoID.Undo

DoCmd.OpenForm "frm_ClientCo", , , , acFormAdd, acDialog
Response = acDataErrAdded
Me.Requery
With Me.RecordsetClone

.FindFirst [InsuranceCoID] = " & NewData & """
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Else
Me.cboInsuranceCoID.Undo

Response = acDataErrContinue
End If
End Sub

Thanks so much for any help with this!
 
J

John W. Vinson/MVP

How can I have the items that are added to my combo box add to the list in
alphebetical order? I currently have it coded to be able to add item on
NotInList event but the item is added to the end of the list. Here is the
code I have now:

Don't do it in your code at all; instead, set the rowsource of the
combo to a Query sorting the records as desired.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top