Brad said:
How do I sort a Text filed that is in outline form
1.3
1.31
1.10
1.10.1
Others have mentioned writing a VBA function to parse out the elements
of the string. As it happens, I wrote such a routine some time ago for
another poster. Here it is:
'----- start of code -----
Function fncHierarchicalElement( _
KeyString As Variant, _
Delimiter As String, _
ByVal ElementNo As Integer) _
As Variant
Dim strKey As String
Dim lngPos As Long
Dim intCount As Integer
If ElementNo < 1 Then
Err.Raise 5
End If
If Len(Delimiter) < 1 Then
Err.Raise 5
End If
fncHierarchicalElement = Null
If IsNull(KeyString) Then
Exit Function
End If
strKey = KeyString
ElementNo = ElementNo - 1
For intCount = 1 To ElementNo
lngPos = InStr(lngPos + 1, strKey, Delimiter, vbBinaryCompare)
If lngPos = 0 Then
If ElementNo = 0 Then
Exit For
Else
Exit Function
End If
End If
Next intCount
strKey = Mid$(strKey, lngPos + 1)
lngPos = InStr(1, strKey, Delimiter, vbBinaryCompare)
If lngPos > 0 Then
strKey = Left$(strKey, lngPos - 1)
End If
fncHierarchicalElement = strKey
End Function
'----- end of code -----
To retrieve, say, the second element of the string, you could have a
calculated field in a query like this:
Part2: fncHierarchicalElement([YourField], ".", 2)
If you need to sort numerically on this field, you'll need to convert
each element to a number; e.g.,
Part2: CInt(Nz(fncHierarchicalElement([YourField], ".", 2), 0))
You'd need to create a calculated field for each of the parts you
anticipate.