I have a text field that stores numbers that may occassionally have letters
after them. I need to be able to sort this field as if it is a number field
even though it holds text. Unfortunately, that is not something I have an
option to change, but I have to find a way to work with it.
The problem comes with the numbers 1-9 falling in the wrong place with the
text sort.
Does anyone have a suggestion on how to correct that in the sorting? The
only thing I came up with was very messy. That was to use nested if
statements to handle 1-9.
I am open to suggestions.
Thanks,
Beth
Allen Browne - 07 Mar 2007 00:09 GMT
Type this expression into the Field row in query design:
Val(Nz([Field1],"0"))
Choose Ascending in the Sorting row under this field.
Val() ignores trailing non-numeric charactrers.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
>I have a text field that stores numbers that may occassionally have letters
>after them. I need to be able to sort this field as if it is a number
[quoted text clipped - 10 lines]
> Thanks,
> Beth
fredg - 07 Mar 2007 00:21 GMT
> I have a text field that stores numbers that may occassionally have letters
> after them. I need to be able to sort this field as if it is a number field
[quoted text clipped - 10 lines]
> Thanks,
> Beth
If the data is like:
8123PLU
23XZ
765KJM
Create a query that will be used as the form's record source.
Add a new column.
SortThis:Val([Fieldname])
Sort by this field.

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail