Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Posts
    1

    Question Auto Increment by 1 Letter


    Ok. I work in a welding shop and we are in the process of creating a database that allows us to keep track of our inventory coming in and going out.
    Each piece of new material we bring in is assigned a Trace Code which is simply three letter. First piece brought in is AAA. Next piece AAB and so on...When you get to AAZ the next one becomes ABA. Ultimately when you get to AZZ your next series is now BAA. Is there a way for me to set up the form to automatically do that?
    I have already set up the form and table and they are named Inventory Receiving List. The field for this data is named Trace Code. Any help anyone could offer would be greatly appreciated.
    Please be mindful in answering that I really am not very strong with formulas and modules.
    Many Many Thanks in advance!!

  2. #2
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    An easy way to do this would be to have a cross-reference table where you have 2 fields, ID and LetterID Field. Your ID field would be numeric and your letter id field would be in the format that you mentiioned AAA, AAB etc. You would then have an Auto-ID field in your main table that would perform a lookup on the ID in that table. For example, if the Auto-ID field was 2 then, it would pull AAB. This probably is not the best way to set it up but it's quick and easy.

    Quote Originally Posted by Cinquefoil22 View Post
    Ok. I work in a welding shop and we are in the process of creating a database that allows us to keep track of our inventory coming in and going out.
    Each piece of new material we bring in is assigned a Trace Code which is simply three letter. First piece brought in is AAA. Next piece AAB and so on...When you get to AAZ the next one becomes ABA. Ultimately when you get to AZZ your next series is now BAA. Is there a way for me to set up the form to automatically do that?
    I have already set up the form and table and they are named Inventory Receiving List. The field for this data is named Trace Code. Any help anyone could offer would be greatly appreciated.
    Please be mindful in answering that I really am not very strong with formulas and modules.
    Many Many Thanks in advance!!

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    manually that would take forever manually. 26^3 combinations.

    Hopefully someone strong in VBA can help put this into working code but heres the logic of what I would do
    A = 1
    B = 2
    ...
    Z = 26

    dim 3 ints, hun (hundreds place), ten (tens place) one (ones place)

    hun = 1, ten = 1, one = 1

    fill a recordset with the following logic
    do while one < 27
    current record = hun & ten & one
    one = one +1
    loop
    then once that's done, increment ten +1 and loop again, once ten = 27, increment hun +1 and keep going.

    Logic is since you cant count by letter, you count by number and assign a letter to the number before entering into the table.

    If anyone can mock up this in VBA, I think it would be great to store in the code repository.

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,046
    Hi,
    try

    Public Function GetNextChar(strCode As String) As String

    Dim strChars As String
    Dim strChar As String
    Dim intPos As Integer
    Dim strResult As String

    strChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    strChar = Right(strCode, 1)
    If strChar < "Z" Then
    intPos = InStr(1, strChars, strChar)
    strChar = Mid(strChars, intPos + 1, 1)
    strResult = Left(strCode, 2) & strChar
    Else
    strChar = Mid(strCode, 2, 1)
    If strChar < "Z" Then
    intPos = InStr(1, strChars, strChar)
    strChar = Mid(strChars, intPos + 1, 1)
    strResult = Left(strCode, 1) & strChar & "A"
    Else
    strChar = Left(strCode, 1)
    If strChar < "Z" Then
    intPos = InStr(1, strChars, strChar)
    strChar = Mid(strChars, intPos + 1, 1)
    strResult = strChar & "AA"
    Else
    strResult = "###" 'last code is used
    End If
    End If
    End If
    GetNextChar = strResult


    End Function

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    yea, do what Noella mentioned. It's much cleaner than my brute force C/C++ logic

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

Similar Threads

  1. Auto increment when the form opens
    By Lynn in forum Forms
    Replies: 13
    Last Post: 04-11-2010, 12:49 PM
  2. Checking for trailing letter
    By jgelpi16 in forum Queries
    Replies: 2
    Last Post: 03-23-2010, 09:27 AM
  3. Replies: 2
    Last Post: 12-08-2009, 01:19 PM
  4. From letter from a report
    By LANCE in forum Reports
    Replies: 4
    Last Post: 07-04-2009, 09:32 AM
  5. Auto-increment for non-100% numerical fields
    By supernoob in forum Access
    Replies: 0
    Last Post: 05-03-2007, 09:44 PM

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