ChrisO
Registered User.
- Local time
- Tomorrow, 01:52
- Joined
- Apr 30, 2003
- Messages
- 3,202
For Pat.
Called as:-
SELECT tblSomeTable.DrawingNumber, SortBy([DrawingNumber]) AS SortedBy
FROM tblSomeTable
ORDER BY SortBy([DrawingNumber]);
It complies with the stated requirements but I think it verges on the impossible for all possible combinations.
For example: we would need to know how to handle such entries as E20.
It’s just a start…
Regards,
Chris.
Code:
[color=green]'1
'10
'100
'2
'20
'3 a
'4D-1
'E3-2
'E10-1
'are all possibilities and should end up as
'1
'2
'3 a
'4D-1
'10
'20
'100
'E3-2
'E10-1[/color]
Public Function SortBy(ByVal vntIn As Variant) As Variant
Dim lngIndex As Long
Dim strTemp As String
Const MaxLen As Long = 100
Const PadChr As String = "_"
If Len(vntIn) Then
For lngIndex = 1 To Len(vntIn)
If IsNumeric(Mid(vntIn, lngIndex, 1)) Then
strTemp = strTemp & Mid(vntIn, lngIndex, 1)
Else
Exit For
End If
Next lngIndex
If Len(strTemp) Then
SortBy = String(MaxLen - Len(strTemp), PadChr) & strTemp
Else
SortBy = String(MaxLen - Len(vntIn), PadChr) & vntIn
End If
End If
End Function
SELECT tblSomeTable.DrawingNumber, SortBy([DrawingNumber]) AS SortedBy
FROM tblSomeTable
ORDER BY SortBy([DrawingNumber]);
It complies with the stated requirements but I think it verges on the impossible for all possible combinations.
For example: we would need to know how to handle such entries as E20.
It’s just a start…
Regards,
Chris.