format field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • didacticone
    Contributor
    • Oct 2008
    • 266

    #1

    format field

    i have a field with numbers in it and was wondering if i can do a query to only keep the last 4 digits in the field. thanks!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by didacticone
    i have a field with numbers in it and was wondering if i can do a query to only keep the last 4 digits in the field. thanks!
    Is it a Whole Number Field (INTEGER, LONG) or Floating Point (SINGLE, DOUBLE)?

    Comment

    • didacticone
      Contributor
      • Oct 2008
      • 266

      #3
      its a long integer field

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        I guess last 4 digits of long integer is remainder of division by 10000.

        = SomeLongInteger Number mod 10000

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by didacticone
          its a long integer field
          I'm running out the door, and I'm sure that there is an easier way, but here is what I come up with in a flash:
          Code:
          Public Function fFormatLong(lngNumber As Long) As String
            fFormatLong = Format(((lngNumber / 10000) - Fix(lngNumber / 10000)) * 10000, "0000")
          End Function
          SAMPLE RESULTS:
          Code:
          Debug.Print fFormatLong(1)
          0001
          
          Debug.Print fFormatLong(27) 
          0027
          
          Debug.Print fFormatLong(892)
          0892
          
          Debug.Print fFormatLong(4320)
          4320
          
          Debug.Print fFormatLong(16230)
          6230
          
          Debug.Print fFormatLong(999992)
          9992
          
          Debug.Print fFormatLong(1234567)
          4567

          Comment

          • OldBirdman
            Contributor
            • Mar 2007
            • 675

            #6
            And with no arithmetic:
            Code:
            Right(Format(lngNumber ,"0000"),4)

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by didacticone
              i have a field with numbers in it and was wondering if i can do a query to only keep the last 4 digits in the field. thanks!
              didacticone, pay absolutely no attention to what that ADezii Character gave as a Reply in Post #5! Do, however, follow OldBirdman's advice in Post #6! (LOL)!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Not forgetting Fish's suggestion in post #4. Hard to beat for a concise answer.

                Comment

                Working...