Results 1 to 8 of 8
  1. #1
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286

    Convert Values in Field to another VALUE? EX: W785 = 7785 due to W = 7

    Hello, i have a link table to an excel spreadsheet. How do i create a query so that it converts IDs which begin with a letter to a number? These are the letters with their respective numeric value: Thanks!

    A = 1
    B = 2
    C = 4
    D = 5
    E = 7
    F = 9

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    W = 7 and E = 7 ?

    Something like:

    NEWID: Switch(Left(ID,1)="A",1, Left(ID,1)="B",2, ...) & Right(ID,3)
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Another option would be to create a table with fields for the two values and join to it in your query. It would be more dynamic in my opinion.

    FYI, I deleted your duplicate threads; please don't start multiple threads on the same topic.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    hanks june, the only problem is that i have both IDs that begin with a Letter and ones that are already beginning with a number. The code above removes the first digit of the ones that are already beginning with a number. is there a way to modify it so that it only looks at IDs beginning with letters?

    ex: If begin with letter a,b,c,d,f, then...code

    thanks!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Okay, IIf(Left(ID,1) LIKE "[A-Z]", ...
    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
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    thanks june! is there a way to add an "else" in there? such as if [A-Z] then code....Else, leave it alone. because currently that column does not contain the numeric values, it does the conversion for the ones that have letters in front but displays a blank field for those that begin with a number

  7. #7
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    nevermind, i just added Left(ID,1)="1",1, for example. thanks for all the help!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    The general syntax of an IIf is:

    IIf(this true, then this, else this)

    Example:

    IIf(x=2, [field name] * 2, [field name])

    IIf(Left(ID,1) LIKE "[A-Z]", Switch(...), ID)

    or

    IIf(IsNumeric(ID), ID, Switch(...))

    My suggestion for an expression entirely within the query could be impractical. After all, there are 26 letters in the alphabet - are all of them used in your data scheme? This would be a very long expression and might exceed string length limit. Might have to build a custom function with VBA and call the function from query.
    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: 5
    Last Post: 08-29-2011, 05:17 PM
  2. Convert field to General Number
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 04-13-2011, 04:54 PM
  3. Replies: 7
    Last Post: 11-13-2010, 08:08 AM
  4. Convert number to fixed length text field
    By tpcervelo in forum Queries
    Replies: 1
    Last Post: 08-02-2010, 07:26 PM
  5. Convert Negative Values to Positive
    By creativefusion in forum Queries
    Replies: 1
    Last Post: 10-21-2009, 02:47 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