Solved

Auto Increment Text Field

Posted on 2014-04-08
4
60 Views
Last Modified: 2016-05-29
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.
0
Comment
Question by:axfernand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39987452
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
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 500 total points
ID: 39987587
this one goes a bit further: (increments to ZZ)

Function getNextValue(vStr As String) As String
  Dim vChar As Long, firstChar As String, secondChar As String
  firstChar = Left(vStr, 1)
  secondChar = IIf(Len(vStr) = 2, Right(vStr, 1), "")
  If Asc(secondChar) = 90 And Asc(firstChar) = 90 Then MsgBox "We have a ZZ problem!", vbCritical
  If Asc(secondChar) < 90 Then
    secondChar = Chr(Asc(Right(vStr, 1)) + 1)
  Else
    firstChar = Chr(Asc(firstChar) + 1)
    secondChar = Chr(65)
  End If
  getNextValue = firstChar & secondChar
End Function
0
 

Author Comment

by:axfernand
ID: 40002376
Hi Guys,

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question