Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Numbers in Text Field

Status
Not open for further replies.

aids2

Technical User
Mar 20, 2003
18
AU
I know there have been questions on this subject previously however the fix doesnt seem to work for me.
I have data in a field like AD/DHC-8/1 and AD/DHC-8/100, when I print the report from this data the items are not listed sequentially like I need. I cannot edit the data as its imported from another program on a weekly basis.
How can I sort this data to produce reports that go from 1 to 100 in the correct order?
 
If you base your report on a query instead of the table itself, you can use the Mid() and/or Instr() functions to parse out the part of the value you need for sorting.

If the field always begins with AD/DHC-8/ (nine characters), Mid(fieldName,10) would return the numbers at the end.


HTH



When Galileo theorized that Aristotle's view of the Universe contained errors, he was labeled a fool.
It wasn't until he proved it that he was called dangerous.
[wink]
 
Thanks for the reply, I do have the report based on a query but there are 25000+ records and they dont all start with the same prefix, however the common trait is that the numbers I need to sort on are all after the second slash mark.

e.g. AD/DHC-8/1 or AD/Gen/51, so the question is how do I get the query to sort on the data ofter the second slash mark all the time, bearing in mind the text before the mark isnt always the same number of characters?
 
Val(Mid([fieldname],1+InStrRev([fieldname],'/')))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya aids2 . . .
[blue] . . .they dont all start with the same prefix . . .[/blue]
In case you desire a dual sort (sorting on the part before the 2nd [purple]/[/purple], followed by the numeric part), in a query setup two [blue]custom fields[/blue] and sort with these. The first:
Code:
[blue]Sort1:Left([[purple][b]FieldName][/b][/purple], InStrRev([[purple][b]FieldName][/b][/purple]],'/'))[/blue]
The second:
Code:
[blue]Sort2:[b]PHV's[/b] Code[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks for the heads up, I have created 2 fields but keep on getting a syntax error using the statement below
Sort1:Left([TI-NUMBER-TM] , InStrRev([TI-NUMBER-TM]],'/'))

The error is with the first comma.
 
Depending on your locale setting you may have to use a semicolon ([!];[/!]) instead of a comma.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for all the help, it turns out the , had to be replaced with $.
 
aids2 . . .

Not quite sure what ya got there but follow this:
[ol][li]Open the report query in design view.[/li]
[li]Remove the 2 fields you added.[/li]
[li]Remove any current sorting.[/li]
[li]On the [blue]first empty field on the field line[/blue] ([purple]on the right[/purple]), copy/paste the following:
Code:
[blue]Sort1: Left([TI-NUMBER-TM],InStrRev([TI-NUMBER-TM],'/'))[/blue]
[/li]
[li]In the next field on the right, copy/paste the following:
Code:
[blue]Sort2: Val(Mid([TI-NUMBER-TM],1+InStrRev([TI-NUMBER-TM],'/')))[/blue]
[/li]
[li]Set your sorting and you should be set.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top