Sort on field with numbers entered as text (1 Viewer)

RobertLund

New member
Local time
Today, 07:45
Joined
Nov 22, 2021
Messages
4
I have a text field which number the records, and need to sort as if the numbers are actually numbers. If I sort now, I get 1,11,2,21, etc. because the values are text equivalents of numbers. Is there a function, as in Excel’s =Value(text) that I can use?
 

Ranman256

Well-known member
Local time
Today, 02:45
Joined
Apr 9, 2015
Messages
4,337
in the query, add another field to convert the text field: Val([field])
sort on that field.
 

jdraw

Super Moderator
Staff member
Local time
Today, 02:45
Joined
Jan 23, 2006
Messages
15,395
Try sort on CInt(yourfieldname) Where yourfieldname IS NOT NULL. Let us know how it goes.
Better to show us the query sql.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:45
Joined
Oct 29, 2018
Messages
21,531
Is there a function, as in Excel’s =Value(text) that I can use?
Hi. Welcome to AWF!

As @Ranman256 said, you can use the Val() function, but an additional field/column is not required. If you're using the query designer, you can uncheck the Show box. Otherwise, you would use something like.
SQL:
SELECT ... ORDER BY Val(TextField)
Cheers!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:45
Joined
May 7, 2009
Messages
19,246
Val() will not work for Null values, so you need to fix the code:

ORDER BY Val([fieldname] & "")
 

RobertLund

New member
Local time
Today, 07:45
Joined
Nov 22, 2021
Messages
4
I have a text field which number the records, and need to sort as if the numbers are actually numbers. If I sort now, I get 1,11,2,21, etc. because the values are text equivalents of numbers. Is there a function, as in Excel’s =Value(text) that I can use?
thank you everyone for your help with this. I do have NULL record values to eliminate in the table, so this is the query:

SELECT tblSheetMusic.FirstHitsNumber, tblSheetMusic.Title
FROM tblSheetMusic
WHERE (((tblSheetMusic.FirstHitsNumber) Is Not Null))
ORDER BY Val(tblSheetMusic.FirstHitsNumber);

This does create an unchecked column, and it works fine.

Many thanks for all of your inputs.
Cheers,
Robert
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:45
Joined
Oct 29, 2018
Messages
21,531
thank you everyone for your help with this. I do have NULL record values to eliminate in the table, so this is the query:

SELECT tblSheetMusic.FirstHitsNumber, tblSheetMusic.Title
FROM tblSheetMusic
WHERE (((tblSheetMusic.FirstHitsNumber) Is Not Null))
ORDER BY Val(tblSheetMusic.FirstHitsNumber);

This does create an unchecked column, and it works fine.

Many thanks for all of your inputs.
Cheers,
Robert
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

RobertLund

New member
Local time
Today, 07:45
Joined
Nov 22, 2021
Messages
4
If the field is always an integer, why not change the data type?
I did try that at first, and it worked. But It’s a linked excel table that is not under my control, and I just need to use it as a read only source of information.
 

Users who are viewing this thread

Top Bottom