Results 1 to 5 of 5
  1. #1
    Confu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    3

    Expression trouble

    I've got a field that contains employee Id numbers that I'd like to be able to by, the problem is that temporary employees are given id numbers with a v at the beginning. So id numbers would show as:
    232
    3567
    68901
    V4156


    V24567
    To be able to sort this accurately I'm trying to create an expression that checks if it has the v and if so only takes the numbers from the other side and adds 100000 since no id is in that range and I could still accurately sort with that field.
    I've tried:
    Iif(left([emplid]),1="V",(iif(len([emplid])=6, right([emplid],5)+100000),right([emplid],4)+100000),abs([emplid]))
    Which instead of getting 104156 and 124567
    In place of v4156 and v24567 I just get 100000 for both.

    I've also tried testing:
    Iif(len([emplid])=6,right([emplid],5)+100000), right([emplid],4)+100000)
    Which results with replacing the v like i want but also effects the numbers without the v.

    Edit:
    So right after I posted I tried adding parenthesis at (left([emplid],1))="V" to the top expression and it worked but it still sorts by first number so sort looks like:
    1
    10
    10000
    2
    2000
    When I need:
    1
    2
    10
    2000
    10000
    I've tried using abs() around the whole expression but it doesn't seem to affect it.
    Last edited by Confu; 07-24-2015 at 04:58 AM. Reason: Additional help needed

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Use this.

    Iif(left([emplid],1)="V",iif(len([emplid])=6, CLng(right([emplid],5))+100000,CLng(right([emplid],4))+100000),abs([emplid]))

  3. #3
    Confu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    3
    Quote Originally Posted by lfpm062010 View Post
    Use this.

    Iif(left([emplid],1)="V",iif(len([emplid])=6, CLng(right([emplid],5))+100000,CLng(right([emplid],4))+100000),abs([emplid]))
    I tried inputting that but it says cannot be used in a calculated column. I assume it was CLng function because it doesn't auto fill when I type it in.
    Edit:
    Alright so I was able to input that into criteria of a query but when I sort it still doesn't sort by value but rather first character
    Last edited by Confu; 07-24-2015 at 07:20 AM. Reason: New info

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You really should try to avoid using calculated columns (fields) in a table - use a query instead.

    Put an expression field in your query and use the expression for sorting (you don't have to display it).

    Something like this should work:

    iif(left([emplid],1) = "V", val(mid([emplid,2])), val([emplid]))

  5. #5
    Confu is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    3
    Thanks, solved my problem. Never been proficient at access and its been years since I last used it.

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

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2015, 11:44 AM
  2. Replies: 3
    Last Post: 03-26-2013, 08:51 AM
  3. trouble understanding expression
    By mejia.j88 in forum Queries
    Replies: 4
    Last Post: 02-01-2012, 03:00 PM
  4. Trouble with Expression
    By kctxucop08 in forum Access
    Replies: 1
    Last Post: 07-14-2011, 01:55 AM
  5. Expression trouble
    By ROB in forum Access
    Replies: 2
    Last Post: 06-08-2010, 09:36 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