Re: Sorting numbers in a text field
- From: "raskew via AccessMonster.com" <u28575@uwe>
- Date: Tue, 27 Feb 2007 00:33:42 GMT
Fred -
Neat solution! I'm still puzzling over how the nested Iif works. It looks
like it's missing a False portion. Anyway, it works great. Function
Savenumer(), below, removes non-numeric characters from a string. Utilizing
this added to your SQL appears to sort it as desired.
SELECT
tblBasicData.CombinedText
FROM
tblBasicData
WHERE
((Not (tblBasicData.CombinedText) Is Null))
ORDER BY
IIf(Val([CombinedText])=0,Val(savenumer([CombinedText])))
, IIf(Val([CombinedText])>0,Val([CombinedText]));
***********************************************************************
Function SaveNumer(ByVal pstr As String) As String
'*******************************************
'Purpose: Removes alpha characters from a string
'Coded by: raskew
'Calls: Function IsNumeric()
'Inputs: ? SaveNumer(" t#he *qu^i5ck !b@r#o$w&n 4fo#x ")
'Output: 5
'Note: As written, empty spaces are ignored.
'*******************************************
Dim strHold As String
Dim intLen As Integer
Dim n As Integer
strHold = Trim(pstr)
intLen = Len(strHold)
n = 1
Do
If Mid(strHold, n, 1) <> " " And Not IsNumeric(Mid(strHold, n, 1))
Then
strHold = Left(strHold, n - 1) + Mid(strHold, n + 1)
n = n - 1
End If
n = n + 1
Loop Until Mid(strHold, n, 1) = ""
SaveNumer = strHold
End Function
***********************************************************************
Bob
mpfohl@xxxxxxxxxxx wrote:
It's close but still not quite right. The numbers do fine, but i'd
like the end to look like:
FM 1
FM 3
FM 11
and not, as your way produced.
FM 1
Fm 11
FM 3
But it's very close, thank you. Any suggestions on how to get to the
last step?
[quoted text clipped - 32 lines]I have a text field I want to sort.
Please respond only to this newsgroup.
I do not reply to personal e-mail
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200702/1
.
- References:
- Sorting numbers in a text field
- From: mpfohl
- Re: Sorting numbers in a text field
- From: fredg
- Re: Sorting numbers in a text field
- From: mpfohl
- Sorting numbers in a text field
- Prev by Date: Re: newbie SQL question
- Next by Date: Re: Parameter query not working correct.
- Previous by thread: Re: Sorting numbers in a text field
- Next by thread: Re: newbie SQL question
- Index(es):
Relevant Pages
|
Loading