Results 1 to 5 of 5
  1. #1
    Robert_PW is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    1

    How to grab last two digits from an integer?

    Hello all,



    I hope this is the correct place for this inquiry.

    Question: In the expression builder in MS Access, how can I write a statement that will grab the last two digits of an integer stored number? Just for clarification, the number may only be one digit but I still want it to be two digits (i.e. "9" would be "09", "289" would be "89" etc.). The result has to be stored as a string.

    I've tried the Right() function and Cstr function and I can't get it to result in two digits.

    Thank you,

    Robert

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Wrap your function in the Format() function:

    Format(Whatever, "00")

    will produce a 2-digit number like 09.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    But Format(12345, "00") will still give you 12345, not 45.

    Use the MOD operator in conjunction with the Format:

    Format(Value mod 100,"00"), so Format(12345 mod 100,"00") wil give you 45, and
    Format(12309 mod 100,"00") wil give you 09.

    John

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Certainly, which is why I said to wrap the function that is returning 1 or 2 digits in the Format function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RiVit is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    7
    IIf([Expr1]<10,"0" & [Expr1],Right([Expr1],2))

    Replace Expr1 by variable

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA to grab current subform field value
    By tylerg11 in forum Programming
    Replies: 4
    Last Post: 02-03-2012, 03:24 PM
  2. Replies: 2
    Last Post: 01-10-2012, 06:41 PM
  3. Grab first characters from field
    By sau3-access in forum Access
    Replies: 1
    Last Post: 10-04-2011, 10:40 AM
  4. grab partial data from one cell
    By andiwir in forum Queries
    Replies: 4
    Last Post: 08-10-2011, 08:55 PM
  5. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums