Perhaps you could call the following function in a calculated field (
MySortField: ReturnSortValueForAlphaNumerics([FieldName]) ) in your query,
and do Ascending sort on this calculated field:
Public Function ReturnSortValueForAlphaNumerics(ByVal strOriginal) As String
' ** LOGIC IS TO REPLACE EACH CHARACTER IN THE ORIGINAL STRING WITH A MULTI-
' ** CHARACTER "NUMBER" STRING THAT WILL SORT THE ORIGINAL STRING CORRECTLY.
' Ken Snell :: April 26, 2007
Dim lngLoc As Long
Dim strSort As String, strT As String, strLoc As String
Const strDash As String = "-"
Const strNum As String = "[0-9]"
lngLoc = 1
strT = Left(strOriginal, 1)
strSort = Format(Abs(Not strT Like strNum) & IIf(IsNumeric(strT), "00",
Asc(strT)), "000")
strT = ""
Do
strLoc = Mid(strOriginal, lngLoc, 1)
If strLoc Like strNum Then
Do
strT = strT & strLoc
lngLoc = lngLoc + 1
strLoc = Mid(strOriginal, lngLoc, 1)
Loop While strLoc Like strNum
strSort = strSort & Right("!!!!!!!!!!" & CStr(Val(strT)), 10)
strT = ""
Else
If strLoc = strDash Then
strSort = strSort & "AAA"
Else
strSort = strSort & strLoc & "ZZ"
End If
lngLoc = lngLoc + 1
End If
Loop Until lngLoc > Len(strOriginal)
ReturnSortValueForAlphaNumerics = strSort
End Function
--
Ken Snell
<MS ACCESS MVP>
HilltopMG said:
Sorry for the confusion, new to posting.
Here's the SQL statement being used:
SELECT DISTINCTROW tblPackaging.*, tblPackaging.PAKNo
FROM tblPackaging
ORDER BY Left([PAKNO],2), IIf(IsNumeric(Left([PAKNo],7)),IIf(Not
IsNumeric(Right([PAKNo],1)),1,IIf(Len([PAKNo])=7,100,1)),1),
tblPackaging.PAKNo;
Some sample data looks like this:
609990
6000010
6000020
.
.
6001120
6001130
6001140
610010
610020
610030
.
.
.
a*1000-11
a*1000-12
.
.
.
a~1PK018
a~1PK036
.
.
.
Hope you can help me.
Thanks.
John Vinson said:
I'm puzzled too.
Please post some examples of such Package ID numbers and indicate how
you would like them sorted, and please also post the SQL of the query
that's giving you the data mismatch error message.
John W. Vinson[MVP]