Link to home
Start Free TrialLog in
Avatar of axfernand
axfernand

asked on

Auto Increment Text Field

Hello,

I have a 2 character text field that I need to increment automatically in a table via VBA.  For example, I have a record with the pseudo key AA that I need to create a new record for under pseudo key AB.  I have thousands of records that I need to do this for.  Here are some examples of the keys I'm working with: AA, CB, AZ, ZA, PQ, et...the records that are created look at the alphabet for the second digit and adds the next consecutive letter.   How would I be able to do this via VBA?

Thank you.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you need to use VBA codes to achieve this

test this function,

Function getNextValue(vStr As String)
Dim vChar As Long, firstChar As String
firstChar = Left(vStr, 1)
vChar = Asc(Right(vStr, 1))

getNextValue = firstChar & Chr(vChar + 1)
End Function

Open in new window

?getNextValue("AA")
AB
ASKER CERTIFIED SOLUTION
Avatar of COACHMAN99
COACHMAN99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of axfernand
axfernand

ASKER

Hi Guys,

Haven't had a chance to apply your code but will do next week.  Thanks for the responses.