Wednesday, 21 August 2013

Alphabetize a comma delimited string in Access

Alphabetize a comma delimited string in Access

I'm not quite sure where to head from here, I have a small bit of code
that loops through a table and writes all of the field names to a string
for use as a value rowsource in a combo box. I'd like these items to be
alphabetized but am not quite sure the best way to go about doing this
with a string variable (or in the combo boxes RowSource property).
Any thoughts or suggestions on the best way to do this?
If it's helpful here is the code I have:
Dim strFields As String
Dim fldTemp As Field
Dim intCount As Integer
Dim setData As DAO.Recordset
Set setData = CurrentDb.OpenRecordset("SELECT * FROM tblEnvironment WHERE
1 = 2")
For Each fldTemp In setData.Fields
strFields = strFields & ", " & fldTemp.Name
Next
strFields = Mid(strFields, 3)
For intCount = 1 To 10
Controls("cboField" & intCount).RowSource = strFields
Next
StrFields is what I would like to alphabatize. Thanks in advance!

No comments:

Post a Comment