Results 1 to 11 of 11
  1. #1
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100

    Creating Masks or Formats to Display Leading Characters of a Text String


    Hi, If it's uncomplicated to achieve, I'd like to display all characters to the left of a decimal place in a text string. I know there's expressions to extract and trim but was just curious of this was possible. Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Try the InStr() function to find the decimal within the Left() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Cheers pbaldy, will look at that. Thx.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    or use the int function

    int("123456.345466")

    returns 123456

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Just one word of caution about using the Int function
    It works fine with positive numbers but may not give what you want with negative values
    Int(1234.56)=1234 BUT Int(-1234.56) = -1235

    You may find the Fix function better for your purposes
    Fix(1234.56)=1234 AND Fix(-1234.56) = -1234

    If you experiment with different decimal point values, you'll see the result remains the same
    e.g. Int(-1234.01) = -1235 ; Fix(-1234.01) = -1234

    BTW the "" marks aren't needed with either function as you are dealing with numbers
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    I'd forgotten about Fix

    I included the quotes because the OP said he had a text string and I wanted to demonstrate the int function works on (valid) strings

  7. #7
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Hi Ridders, It seems reading Google that Int, Round & Fix are numeric centric and don't apply to text strings. That's ok, it wasn't critical. Cheers, guys. My learning curve goes up a notch. Several in fact.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Ajax is of course correct in stating that Int will work (with quotes) if the text string is just a number like 1234.56 ... as will Fix.
    I was assuming you had already stripped the number part out of your string.

    It is certainly the case that the functions Int, Fix and Round will not work on a text string like 'A is 100.53 km from B' unless you do first separate out the 100.53 part.
    You could do that by e.g. searching for the first numeric character 0-9 or + or - then extracting everything before the following decimal point
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    It seems reading Google that Int, Round & Fix are numeric centric and don't apply to text strings
    don't believe everything you read - if in doubt, try it.

    if you have something like '123.456 km' use the val function first

    fix(val("123.456 km"))

    will return 123

    works for any string that starts with numerical values

  10. #10
    DigitalAdrenaline is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2012
    Posts
    100
    Ahh, ok. All my strings are text. But that function's handy to know. Thx.

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    a string by definition is text the question should be why are you storing numbers as text? You can't sort numerically, table size is bigger, indexing slower

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

Similar Threads

  1. Replies: 7
    Last Post: 04-20-2018, 03:29 PM
  2. Creating a Text Box to Display a Running Total
    By Art_Of_War in forum Access
    Replies: 16
    Last Post: 01-03-2018, 10:49 PM
  3. Replies: 6
    Last Post: 10-18-2013, 07:30 AM
  4. Issues with Text Box formats and expressions
    By AndrewsPanda in forum Reports
    Replies: 3
    Last Post: 09-28-2011, 11:32 PM
  5. Problems with creating Multiple Input Masks
    By deiniolj in forum Programming
    Replies: 8
    Last Post: 01-26-2011, 03:44 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