Function sortedfields(rs As Recordset) As String 'assumes we have to concatenate all fields from the current record ' in ascending order. Dim i As Integer, res() As Variant, cRes As String, nTop As Long Const cSep = "," 'this character or string will separate the entries in the resulting string 'determine the number of fields nTop = rs.Fields.Count 'size the array ReDim res(nTop) 'get the values from the record into the array For i = 1 To nTop res(i) = rs(i) Next 'sort the array Dim h As Integer, j As Integer, hold As Variant For i = 1 To nTop - 2 If res(i) > res(i + 1) Then 'next is smaller. Pull it up as far as reasonable h = i hold = res(i + 1) Do h = h - 1 Loop Until h = 0 Or res(h) < hold h = h + 1 'h now points to next larger item For j = i To h Step -1 res(j + 1) = res(j) 'push block down Next res(h) = hold End If Next 'concatenate and return cRes = "" For i = 1 To nTop If cRes <> "" Then cRes = cRes & cSep cRes = cRes & res(i) Next End Function