I have a list of items this is just a sample:
(C)ADAPTER FEMALE 1/2"
(C)ADAPTER FEMALE 3/4"
(C)ADAPTER FEMALE 1"
(C)ADAPTER FEMALE 2"
(C)ADAPTER FEMALE 3"
I want it to sort as above but it sorts
(C)ADAPTER FEMALE 1"
(C)ADAPTER FEMALE 1/2"
(C)ADAPTER FEMALE 2"
(C)ADAPTER FEMALE 3"
(C)ADAPTER FEMALE 3/4"
I understand why I just don't have a solution to get it to sort the way I
want.
Any ideas?
Thanks
For data that looks like this:
(C)ADAPTER FEMALE 1/2"
(C)ADAPTER FEMALE 3/4"
(C)ADAPTER FEMALE 1"
(C)ADAPTER FEMALE 2"
(C)ADAPTER FEMALE 3"
The following solution depends on there being a space (at least one
space) immediately before the numerical part of the data.
You'll need to be able to create and use a function to understand
this.
It works like this ...
(I have kept it a simple as I can and deliberately used some extra
variables to try to make it clearer what is going on)
You need a numeric field (column) in your table (I called the table
tblTestData) set to be Number and Double.
I called this TestValue.
I have assumed the data is in a field called TestText.
Now, for each row of data ...
find the length of the data string
start at the right hand end and step back through the string until you
reach a space character
the numeric part of the string is all the stuff from the space to the
right hand end of the string
use the Eval function to convert this to a number and store it in the
TestValue field.
There is NO error checking built into this small function!
You can then sort on the TestValue field to get the order you want.
Public Function GetValueFromText()
Dim db As database
Dim rs As Recordset
Dim xText As String
Dim n As Long
Dim xCount As Long
Dim xTextValue As Double
Dim xPart As String
Set db = CurrentDb
Set rs = db.openrecordset("tblTestData", dbopendynaset)
rs.MoveFirst
Do Until rs.EOF
'Find the length of the string
n = Len(rs!TestText)
'now step (backwards) through the string from the right hand end
looking for a space character
For xCount = n To 1 Step -1
xPart = Right(rs!TestText, xCount)
'is the first character in xPart a space?
If Left(xPart, 1) = " " Then
rs.Edit
rs!TestValue = Eval(xPart)
rs.Update
End If
Next
rs.MoveNext
Loop
End Function