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 / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

Ordinal numbers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lulu - 08 Mar 2005 19:13 GMT
Anyone have a suggestion for easily formatting numbers as ordinals in an
Access report?

Muy thanks.
Rick B - 08 Mar 2005 19:22 GMT
Are you saying you want line numbers in your report? Not sure what you are
asking for.  Give us an example.

     or?di?nal num?ber (plural or?di?nal num?bers)
     noun

     1. number showing order: a number used to show the relative position
of something or somebody in a sequence. "First" and "second" are ordinal
numbers.
     Also called  ordinal

     2. mathematics logic size and order of a set: a measure of the size of
an ordered set in addition to the order of its elements

> Anyone have a suggestion for easily formatting numbers as ordinals in an
> Access report?
>
> Muy thanks.
Lulu - 08 Mar 2005 20:33 GMT
Formatting as Ordinal means if a value in a text box is 7 the value in the
report will read 7th; 11 would read 11th and 21 would read 21st

> Are you saying you want line numbers in your report? Not sure what you are
> asking for.  Give us an example.
[quoted text clipped - 14 lines]
> >
> > Muy thanks.
Brendan Reynolds - 08 Mar 2005 20:53 GMT
I have only briefly tested this, it seems to work, but I can't guarantee
that there are no exceptions that I haven't anticipated ...

Public Function ToOrdinal(ByVal TheNumber As Variant) As String

   Dim strChar As String

   If Len(TheNumber & vbNullString) > 0 Then
       If Len(TheNumber) > 1 Then
           If Mid$(TheNumber, Len(TheNumber) - 1, 1) = "1" Then
               ToOrdinal = TheNumber & "th"
           Else
               Select Case Right$(TheNumber, 1)
               Case "1"
                   ToOrdinal = TheNumber & "st"
               Case "2"
                   ToOrdinal = TheNumber & "nd"
               Case "3"
                   ToOrdinal = TheNumber & "rd"
               Case Else
                   ToOrdinal = TheNumber & "th"
               End Select
           End If
       Else
           Select Case Right$(TheNumber, 1)
           Case "1"
               ToOrdinal = TheNumber & "st"
           Case "2"
               ToOrdinal = TheNumber & "nd"
           Case "3"
               ToOrdinal = TheNumber & "rd"
           Case Else
               ToOrdinal = TheNumber & "th"
           End Select
       End If
   Else
       ToOrdinal = vbNullString
   End If

End Function

Here's an example of it's use in a query (in production, it might be better
to use it in the ControlSource of a text box on the report, but a query is a
good way of testing it with a range of different numbers) ...

SELECT tblTest.TestNumber, ToOrdinal([TestNumber]) AS TheOrdinal
FROM tblTest;

Signature

Brendan Reynolds (MVP)

> Formatting as Ordinal means if a value in a text box is 7 the value in the
> report will read 7th; 11 would read 11th and 21 would read 21st
[quoted text clipped - 21 lines]
>> >
>> > Muy thanks.
Lynn Trapp - 08 Mar 2005 21:07 GMT
This function should do what you want:

Function Ordinal_Numbers(P_Numeric As String) As String
Dim V_Ordinal As String
Dim V_Numeric As String
If Right(P_Numeric, 2) = "11" Or Right(P_Numeric, 2) = "12" Or
Right(P_Numeric, 2) = "13" Then
 Ordinal_Numbers = "th"

Else
V_Numeric = Right(P_Numeric, 1)

Select Case V_Numeric
 Case "1"
   V_Ordinal = "st"
 Case "2"
   V_Ordinal = "nd"
 Case "3"
   V_Ordinal = "rd"
 Case Else
   V_Ordinal = "th"
End Select
Ordinal_Numbers = V_Ordinal
End If
End Function

Call the function from a query like this:

OrdinalNumber: [YourNumberField] & Ordinal_Numbers(CStr([YourNumberField]))

Signature

Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Big List: www.ltcomputerdesigns.com/JCReferences.html

> Formatting as Ordinal means if a value in a text box is 7 the value in the
> report will read 7th; 11 would read 11th and 21 would read 21st
[quoted text clipped - 21 lines]
>> >
>> > Muy thanks.
Lulu - 09 Mar 2005 15:09 GMT
Pretty much what I thought.  Your version is very tidy, Lynn.  Many thanks.  
Perhaps some future version of Access would think of this as a needed
Built-In Function.

> This function should do what you want:
>
[quoted text clipped - 51 lines]
> >> >
> >> > Muy thanks.
Lynn Trapp - 09 Mar 2005 16:37 GMT
> Pretty much what I thought.  Your version is very tidy, Lynn.  Many
> thanks.
> Perhaps some future version of Access would think of this as a needed
> Built-In Function.

Lulu,
I'm glad that helps you. Brendan's version is a bit more robust than mine,
as it checks for a null entry in the number field. You could put this
function in a database and use it as an add-in for any and all of your
databases by setting a reference to it--almost as good as a Built-In.

Signature

Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Big List: www.ltcomputerdesigns.com/JCReferences.html 

 
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.