Solved

Order by

Posted on 2016-10-15
8
49 Views
Last Modified: 2016-10-16
Any way to stop access ordering numbers incorrectly

Please see attached
Capture6.PNG
0
Comment
Question by:DatabaseDek
  • 4
  • 3
8 Comments
 
LVL 20

Expert Comment

by:n2fc
ID: 41844960
It is using an alphabetic sort instead of numeric... You would have to change the contents of that field to use a 2 (or 3 digit, if the number portion exceeds 99) after the letter!
0
 

Author Comment

by:DatabaseDek
ID: 41844970
How do you change to numeric?

Derek
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41844971
Specify this:

    Order By Val(Mid([Door Number],2))

/gustav
1
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:DatabaseDek
ID: 41845541
If I have

DS6ST and
DS4ST it does not order correctly. Is it possible to order this correctly? Bearing in mind the user could enter any number of alpha numeric combinations
0
 

Author Comment

by:DatabaseDek
ID: 41845542
Gustave

Your suggestion worked well on my previous example
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41845553
Then you may have to use a function like this:
Public Function TrimNumString( _
  ByVal strNumString As String, _
  Optional ByVal strDecimalChr As String, _
  Optional ByVal booAcceptMinus As Boolean) _
  As String

' Removes any non-numeric character from strNumString including hexadecimal characters.
' If strDecimalChr is specified, first occurrence of this is not removed.
' If booAcceptMinus is True, a leading or trailing minus sign is accepted.
'
' 1999-08-27. Cactus Data ApS, CPH.
' 2001-06-21. Speed optimized for large string (64 K).
' 2003-12-10. intOffset changed to lngOffset.
  
  Const cbytNeg   As Byte = 45  ' "-"
  
  Dim lngPos      As Long
  Dim lngLen      As Long
  Dim lngOffset   As Long
  Dim booDec      As Boolean
  Dim booNeg      As Boolean
  Dim bytChr      As Byte
  Dim bytDec      As Byte
  Dim strNum      As String
  
  strNumString = Trim(strNumString)
  lngLen = Len(strNumString)
  If lngLen > 0 Then
    If Len(strDecimalChr) > 0 Then
      bytDec = Asc(strDecimalChr)
    End If
    ' Create empty result string of maximum possible length.
    strNum = Space(lngLen)
    
    For lngPos = 1 To lngLen
      bytChr = Asc(Mid(strNumString, lngPos, 1))
      Select Case bytChr
        Case 48 To 57
          ' Digit.
        Case bytDec
          ' Decimal point.
          If booDec = False Then
            ' One decimal point only.
            booDec = True
          End If
        Case cbytNeg
          ' Minus sign.
          bytChr = 0
          If booAcceptMinus = True And booNeg = False Then
            If Len(Trim(strNum)) = 0 Or lngPos = lngLen Then
              bytChr = cbytNeg
              ' One minus sign only.
              booNeg = True
            End If
          End If
        Case Else
          ' Ignore any other character.
          bytChr = 0
      End Select
      If bytChr > 0 Then
        ' Append accepted character by inserting it in result string.
        lngOffset = lngOffset + 1
        Mid(strNum, lngOffset) = Chr(bytChr)
      End If
    Next
  End If
  
  ' Trim and return result string.
  TrimNumString = Left(strNum, lngOffset)

End Function

Open in new window

and the expression:

    Order By Val(TrimNumString([Door Number]))

An easier method would be to number the doors with leading zeroes and fixed length numbers like D03 and DS04ST.

/gustav
0
 

Author Closing Comment

by:DatabaseDek
ID: 41845817
What a performance eh!

Thanks Gustav. Excellent
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41845850
You are welcome!

/gustav
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
File.Search issue 8 35
How can I have an Calculator icon for a button? 36 67
Calculated field not displaying as currency on form 4 22
Help formatting a report 3 21
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question