Results 1 to 3 of 3
  1. #1
    Cyberwombat is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    1

    Calculated field to change a string to a number


    I have a simple Access database that I use to keep track of persons assigned to projects. The project numbers can be a mix of alphanumeric data such as 3205.A, 3205.11 etc. Currently I have the field type set to text but that results in abnormal sorting: 3205.100 comes before 3205.11, for example.

    I had hoped to overcome this by using a calculated field to convert the value in the project number from a text to a numeric value, but VAL() is not a valid function for a calculated field.

    Is there another way to deal with this? Access tables do not have triggers like SQL Server uses, and I'm not about to migrate to SQL just for that functionality.

    Thanks - Dan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Do calc to fix the value in query.

    Calculated fields were intended for simple calcs like: Price * Quantity
    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
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you're storing this as a text value you would likely have to break the string into two parts, what comes before the decimal and what comes after, then sort your data based on the left and right parts of the string.


    so

    left([Fieldname], instr([Fieldname], "."))

    might give you the left side and

    right([Fieldname], instrrev([fieldname], ".")

    might give you the right side.

    You will likely have to play around with the second part of the left and right function to properly show string you want then pehaps change them to integers (for sorting purposes) like this:

    cint(left([Fieldname], instr([Fieldname], ".")))

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

Similar Threads

  1. Replies: 3
    Last Post: 05-26-2013, 08:57 AM
  2. Replies: 0
    Last Post: 10-22-2012, 02:45 PM
  3. Replies: 1
    Last Post: 11-20-2011, 12:11 PM
  4. Replies: 3
    Last Post: 04-19-2011, 06:41 PM
  5. Replies: 1
    Last Post: 02-05-2009, 04:53 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