Results 1 to 7 of 7
  1. #1
    ScoobyMug is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    2

    Calculated Field - Trying to use Chr, what can be used instead?

    I have a calculated field where I am trying to increment the string value by 1.
    Example if the field is 'B', then I want the value to be 'C'. Or if the field is 'L', then the new value would be 'M', and so forth.
    If I try to use the function 'chr', access gives me the error that "The expression cannot be used in a calculated column" ?


    IIf(IsNull([TestSuffixId]),'A',chr(Asc([TestSuffixId]) + 1))

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    You can't use any complex expression in a calculated table field.
    I doubt that what your trying to achieve is best suited to a calculated field to be honest.

    Maybe show us your data and describe what you are trying to end up with and why?

  3. #3
    ScoobyMug is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Dec 2017
    Posts
    2
    thank you for your reply: Let me try to explain:
    I need a field in my table that starts with the letter 'A' and then increment by one letter(B,C,D,ect) according based on a condition.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    If you can calculate it then I wouldn't store it, simply use a query to provide the result you need.
    Storing it means having to update it when one of its dependant values is changed anywhere, and leads to a world of pain.

  5. #5
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    What are you going to do when you get to Z? You repeated what you want to achieve, but not why, and not much about what you're doing (i.e. where this fits into the scheme).
    You might want to rethink this http://allenbrowne.com/casu-14.html
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Generating custom unique identifier is a common topic. Here is one discussion https://www.accessforums.net/showthread.php?t=23329
    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.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Below will work if testsuffixID is a textbox on a form.
    Then perhaps you could run an update query to put testsuffixID into your table. (or an INSERT query if this is adding a record to the table).
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Command2_Click()
        testsuffixID = IIf(IsNull(testsuffixID), "A", Chr(Asc(testsuffixID) + 1))
    End Sub

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

Similar Threads

  1. Replies: 1
    Last Post: 05-22-2017, 05:59 AM
  2. Replies: 8
    Last Post: 01-06-2016, 02:52 PM
  3. Replies: 2
    Last Post: 12-30-2014, 01:32 PM
  4. Replies: 2
    Last Post: 12-15-2013, 02:29 AM
  5. Replies: 3
    Last Post: 02-13-2013, 10:15 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