Results 1 to 11 of 11
  1. #1
    Schon731 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    19

    Drop 1st field value if its a number 1-4

    I have a question. I have a field being pulled and some of the values begin with a number. I would like to display this value but if the value begins with a 1,2,3 or 4 then I want it to DROP that leading number. This is a text field.



    ex I have 1P in the field but I want to display as P

    if the field is 6HM then I want to display 6HM

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:

    IIf(Left([fieldname],1)<5, Mid([fieldname],2), [fieldname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    One solution

    Here's what I would do - I'd have the real value being tied to a text field that I would make invisible.

    Then I would have a visible field whose value comes from the hidden field but drops the leading 1-4 if present. Something like this -
    Code:
    =IIF(Left(txtHidden,1)<"1" OR Left(txtHidden,1)>"4", txtHidden, Right(txtHidden,Len(txtHidden)-1))
    That code seems a little clunky, but should work.

    In a query, you'd replace txtHidden with the actual name of the source field, and name the resulting expression with a fieldname something like "AS myMaskedFieldName".

    Looks like June7 beat me to the enter key.

  4. #4
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    June7 - Is "< 5" going to work in all implementations? I hate having to remember whether "A" or "a" is less than or greater than "1".

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Numbers always sort before letters (ascending order).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Oh, the joys of being a PC person. In EBCDIC (the IBM mainframe collating sequence) "1" is x'F1', "A" is x'C1' and "a" is x'81'.

    Straddling PC and mainframe worlds, I can't count on numbers being before letters. I have to look it up every time, so I always code it so I never have to know.

    By the way, which is less, "5" or 5?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Test expression in the VBA immediate window and they are equal, also "15" is greater than 2 but not greater than "2".

    Numbers in a text field will sort alphabetically - "15" will sort before "2" as well as "a".

    So Schon, you are okay with my expression as long as the number prefix remains one digit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Good to know.

  9. #9
    Schon731 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    19

    Thanks

    Quote Originally Posted by June7 View Post
    Test expression in the VBA immediate window and they are equal, also "15" is greater than 2 but not greater than "2".

    Numbers in a text field will sort alphabetically - "15" will sort before "2" as well as "a".

    So Schon, you are okay with my expression as long as the number prefix remains one digit.

    I will try this monday. Even if the 2nd field is a number it can display as such. In other words if its 24h i want to display 4h so I think your code will work. Thanks.

  10. #10
    Schon731 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    19
    This doesnt exactly work 100%. I tried both ways shown above. It only works when the first character is a number but I have some instances where the first character is a letter like AIC. In those cases I want to see AIC but it just says #Error in those fields. Sorry it took so long to try it out. Thanks.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Consistency of structure is critical for string manipulation.

    #Error may be due to 'Type Mismatch'. Odd, my testing indicates the expression should work.

    Try enclosing the 5 in quote marks

    IIf(Left([fieldname],1)<"5", Mid([fieldname],2), [fieldname])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 6
    Last Post: 01-24-2013, 10:02 PM
  2. Drop Down Field Question
    By tn_developer in forum Access
    Replies: 18
    Last Post: 10-02-2012, 04:22 PM
  3. Replies: 5
    Last Post: 05-25-2012, 12:02 PM
  4. Replies: 7
    Last Post: 10-26-2011, 01:47 PM
  5. Over-writeable drop-down look-up field
    By teirrah1995 in forum Forms
    Replies: 1
    Last Post: 07-29-2011, 03:44 AM

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