Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / June 2007

Tip: Looking for answers? Try searching our database.

sort by surname

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Liddle - 20 Jun 2007 09:37 GMT
when sorting a column of surnames in Access it puts O'NEIL before OATS but
when sorted in Excel it puts OATS before O'NEIL. I have also notice this with
name starting with Mc or Mac.  Is there any way that Access can be made to
sort the same as Excel?
Sprinks - 20 Jun 2007 13:44 GMT
Tony,

What version of Access are you using?  With Access 2002, with the General
sort order specified under the Tools, Options, General tab, Access sorts OATS
before O'Neill as in Excel, ignoring apostrophes and hyphens.  It will,
however, not ignore a space, and will sort O' NEILL before OATS.

In any case, regardless of the version you're using, you can use a custom
function for a calculated field to create a new string, stripped of anything
that is not a letter and sort your data by the calculated field:

Public Function LettersOnly(strWS As String) As String
   Dim i As Integer
   Dim intStrLength As Integer
   Dim astrKeep() As Boolean
   
   strWS = UCase(strWS)
   intStrLength = Len(strWS)
   ReDim astrKeep(intStrLength)
   
   For i = 1 To intStrLength
       If Asc(Mid(strWS, i, 1)) < 65 Or Asc(Mid(strWS, i, 1)) > 90 Then
           astrKeep(i) = False
       Else
           astrKeep(i) = True
       End If
   Next i
   
   LettersOnly = ""
   For i = 1 To intStrLength
       If astrKeep(i) = True Then
           LettersOnly = LettersOnly & Mid(strWS, i, 1)
       End If
   Next i
End Function

Your calculated field would be:

MySortField: LettersOnly([YourNameField])

Hope that helps.
Sprinks

> when sorting a column of surnames in Access it puts O'NEIL before OATS but
> when sorted in Excel it puts OATS before O'NEIL. I have also notice this with
> name starting with Mc or Mac.  Is there any way that Access can be made to
> sort the same as Excel?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.