Results 1 to 8 of 8
  1. #1
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    528

    number field automatically

    Hello Guys
    I have been working on a number field automatically
    I want to add the letters before the numbers


    How?
    I used one of the examples in the Forum, but I can not add the letters or the name of the

    Private Sub Form_Current()
    If Me.NewRecord Then
    Me!InNr.DefaultValue = Nz(DMax("[InNr]", "Table1"), 0) + 1
    End If
    End Sub

    Example
    AW1
    AW2
    AW3

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    You will have to extract the number part, increment the value then combine with text. Then you should deal with situation of blank db, before records input. Here is sample code:

    Code:
    Function GetInNr
        strInNr = Nz(DMax("InNr", "Table1"), "")
        If strInNr = "" Then
            'this accommodates very first generated number of blank database
            strInNr = "AW1"
        Else
            strInNr = "AW" & Mid(strInNr, 2) + 1
        End If
       GetInNr = strInNr
    End Function
    You should be aware that alpha sort rules apply. AW129 will sort before AW2. If you want correct sequence, need placeholder zeros, like: AW002, AW010, AW129.

    How high do you expect this series to get? I have code that builds a sequential identifier but it starts over each year. The series has never exceeded 4500.

    Code:
        strLabNum = Nz(DMax("LabNum", "Submit"), "")
        If strLabNum = "" Then
            'this accommodates very first generated number of blank database
            strLabNum = Year(Date) & "A-0001"
        Else
            'this accommodates change in year
            If Left(strLabNum, 4) = CStr(Year(Date)) Then
                strLabNum = Left(strLabNum, 6) & Format(Right(strLabNum, 4) + 1, "0000")
            Else
                strLabNum = Year(Date) & "A-0001"
            End If
        End If
    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.

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Thank you very much June7
    But it seems to me an error
    Please see DB
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Don't refer to form in DMax, refer to table.

    All domain aggregate functions must refer to table or query, not form or report.

    Why do you need to have this value in table? It can be dynamically generated on report. Textbox on report has a RunningSum property.

    Do you really want to use my exact code? The resulting construct will be like: 2014A-0001
    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.

  5. #5
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Yes
    That good
    Is just a number for the Invoice
    I needed was in the searches also
    What is your opinion
    What is the change DB

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Options:

    1. Use the autonumber value as the invoice number. You can format this to display however you want, such as: "AW" & Format([OrderID], "0000") - no VBA required. However, there is no guarantee the autonumber will be sequential nor that it will be a positive integer (although I have never seen negative).

    2. Use suggested code to generate and store unique identifier

    Decision depends on your requirements. Is the invoice number accountable - meaning must be in sequence with no gaps? Must every number be accounted for? In my case the answer is yes and is why I use the code method.
    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
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Thank you June7
    I am what I want is the serial number of the Invoice
    This figure is before the code for the type of material or the company code
    Where when adding a new date for the invoice number is added before or followed by a new company code

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Then does the suggested code work for you?
    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.

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

Similar Threads

  1. Replies: 7
    Last Post: 01-17-2014, 03:39 AM
  2. Auto number automatically next number
    By wnicole in forum Access
    Replies: 3
    Last Post: 10-17-2013, 08:45 AM
  3. Replies: 1
    Last Post: 10-16-2013, 09:41 AM
  4. Replies: 3
    Last Post: 07-12-2013, 11:53 AM
  5. Replies: 4
    Last Post: 04-18-2011, 07:18 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