Sorting bound Combo Box into alphabetical order

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I have a bound cbo (to ASECContact) with many entries. I
would like to have these entries listed in alphabetical
order. I have tried :

Private Sub Combo137_AfterUpdate()

Dim FilterString As String
FilterString = "ASECContact = """ & Me.Combo137 & """"

DoCmd.ApplyFilter , FilterString

End Sub

but this does not work? I also have the following code on
this cbo. which allows me to enter new information:

Private Sub Combo137_NotInList(NewData As String,
Response As Integer)
Dim db As Database
Set db = CurrentDb

'Ask the user if they want to add to the list
If MsgBox("Do you want to add this entity to the list?",
vbYesNo + vbQuestion, "Add new value?") = vbYes Then

'The user clicked Yes - add the new value
db.Execute "INSERT INTO tblASECContact (ASECContact)
VALUES (""" & NewData & """)", dbFailOnError

'Tell Access you've added the new value
Response = acDataErrAdded

Else

'The user clicked No - discard the new value
Me.Combo137.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue

End If

db.Close
Set db = Nothing
End Sub

Grateful any advice on solving this problem.
thanks
 
What's the row source of the combo - is it a query? If so, then for the field ASECContact, select Ascending in the design view of the query. If the row source is a table, make a query on the table and sort it ascending.

The after update code appears to be applying a filter and not a sort, and the NotInList adds to the list and does nothing for sorting.
 
Make the rowsource of the cbo a query based on the table rather than basing the
cbo on the table. Set the sort order on the appropriate field in the query to
ascending.
 
Back
Top