Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2011
    Posts
    35

    Unanswered: Alphabet increment

    I am trying to assign a unique two letter code to a set of record. From AA..AB..BA....all the way to ...ZZ, how do i go about doing this ??? IN VBA ?? Thank you for the help in advance!

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    Here a Mark 1 verson should point you down the right track Should get your thinking hat going

    we need to use the CHR() and ASC()

    Chr(number) return the letter
    Asc(Letter) return the number


    So here the code
    Code:
    Function Next_Code(ThisCode)
    Dim firstbit As String
    Dim secpit As String
    firstbit = UCase(Left(ThisCode, 1))
    secpit = UCase(Right(ThisCode, 1))
    newsecbit = Chr(Asc(secpit) + 1)
    If newsecbit = "[" Then ' we have pass "Z"
    firstbit = Chr(Asc(firstbit) + 1)
    newsecbit = Chr(Asc("A")) ' only did this so it look like the line above
    End If
    
    Next_Code = firstbit & newsecbit
    End Function
    there is NO ERROR checking ( that your job LOL)
    you need to put a Stop
    if you pass "ZZ" you get "[A"

    cope code into module save it

    then to get the next code pass the current code

    New_Code = Next_Code("AA")

    New_Code = "AB"

    in query just go
    New_Code:Next_Code(CurrentCodeFeildName)
    Last edited by myle; 05-23-12 at 11:20. Reason: spelling
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Dec 2011
    Posts
    35
    Thank you for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •