A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Text field sort question



 
 
Thread Tools Display Modes
  #1  
Old October 10th, 2008, 07:51 PM posted to microsoft.public.access
Brucels
external usenet poster
 
Posts: 126
Default Text field sort question

Windows Explorer (Windows XP) sorts a group of files as follows:
1995.203.22.1.tif
1995.203.22.2.tif
1995.203.22.3.tif
1995.203.22.4.tif
1995.203.22.5.tif
1995.203.22.6.tif
1995.203.22.7.tif
1995.203.22.8.tif
1995.203.22.9.tif
1995.203.22.10.tif
1995.203.22.11.tif
1995.203.22.12.tif


The same group, entered in an Access 2002 table (with the field formatted as
a text field), sorts as follows:
1995.203.22.1.tif
1995.203.22.10.tif
1995.203.22.11.tif
1995.203.22.12.tif
1995.203.22.2.tif
1995.203.22.3.tif
1995.203.22.4.tif
1995.203.22.5.tif
1995.203.22.6.tif
1995.203.22.7.tif
1995.203.22.8.tif
1995.203.22.9.tif

Is there any way of changing the Access sort to match the Explorer sort
without having to manually insert zeroes?

Thanks,
Bruce

  #2  
Old October 10th, 2008, 09:12 PM posted to microsoft.public.access
fredg
external usenet poster
 
Posts: 4,386
Default Text field sort question

On Fri, 10 Oct 2008 11:51:14 -0700, Brucels wrote:

Windows Explorer (Windows XP) sorts a group of files as follows:
1995.203.22.1.tif
1995.203.22.2.tif
1995.203.22.3.tif
1995.203.22.4.tif
1995.203.22.5.tif
1995.203.22.6.tif
1995.203.22.7.tif
1995.203.22.8.tif
1995.203.22.9.tif
1995.203.22.10.tif
1995.203.22.11.tif
1995.203.22.12.tif


The same group, entered in an Access 2002 table (with the field formatted as
a text field), sorts as follows:
1995.203.22.1.tif
1995.203.22.10.tif
1995.203.22.11.tif
1995.203.22.12.tif
1995.203.22.2.tif
1995.203.22.3.tif
1995.203.22.4.tif
1995.203.22.5.tif
1995.203.22.6.tif
1995.203.22.7.tif
1995.203.22.8.tif
1995.203.22.9.tif

Is there any way of changing the Access sort to match the Explorer sort
without having to manually insert zeroes?

Thanks,
Bruce


In a table, No.
However no one should be looking at the table anyway.
Create a query with all of the fields you have in the table.
Add a new column to the grid.
SortThis:Val(Replace([FieldName],".",""))
Sort the query on this SortThis field.

Now use this query as the record source for your Form or Report.
Remember, however, that the sort order of a query is irrelevant to the
Sort order of a Report, so make sure you use the SortThis field in the
Report's Sorting and Grouping dialog.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #3  
Old October 11th, 2008, 03:41 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 2,364
Default Text field sort question

I don't think Fred's solution will work as desired. With the limited
example set it should work, but with a sample that includes

1995.203.21.1.tif
1995.203.21.12.tif
1995.203.23.1.tif

You will probably see results that are not satisfactory. I would guess
that to get the sorting you want you are going to need a custom function
to create a sort value or you will need to insert the zeroes.

This one is specific to your situation, but it can be generalized.

Public Function fSortSpecial(strIn, _
Optional strDelimit As String = ".", _
Optional LnumSize As Long = 3) As String

'strDelimit = character(s) used to split string
'lNumsize = minimum number of characters to use for number string
'This function is designed to handle only integer number strings
Dim vSplit As Variant
Dim strReturn As String
Dim i As Long
Dim sFormat as string

sFormat = String(LnumSize,"0")
If Len(strIn & "") = 0 Then
fSortSpecial = ""
Else
vSplit = Split(strIn, strDelimit)
For i = LBound(vSplit) To UBound(vSplit)
If IsNumeric(vSplit(i)) Then
strReturn = strReturn & _
Format(Val(vSplit(i)),sFormat) & strDelimit
Else
strReturn = strReturn & vSplit(i) & strDelimit
End If
Next i

fSortSpecial = strReturn

End If
End Function
  #4  
Old October 29th, 2008, 07:47 PM posted to microsoft.public.access
Ryan D[_2_]
external usenet poster
 
Posts: 1
Default Text field sort question

this code is excately what i need, however i need the function to use two "strDelimit" variables, spitting the string based on two different characters, a "-" and a ".", can anyone help me? thank you.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.