Results 1 to 3 of 3
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Creating a consecutive number

    Hi everyone,

    I have created an event to create a consecutive number depending on the existance of the record for the product. It uses the "Product", "Date" and "consecutive", I mean



    If Product1 were called with the code Pro1 and Product2 were called Pro2, my record ID would be something like this

    PRO1-200420-001
    PRO1-200420-002
    PRO2-200420-001

    '****************************
    Dim Zero As String
    Dim sDate As String
    Dim BU As String
    Dim sPrecode As String
    Dim Possible_Consecutive_ID As Long 'I don't know if "long" is affecting since after 10 won't continue the 11 and further in my code...
    Dim Clave As String

    'Vaues
    Zero = "0"

    sDate = Format(Date, "yymmdd")

    BU = DLookup("[Codigo]", "[Linea_Produccion]", "[LineaProduccion]= '" & Me.Linea_Produccion & "'")

    Me.PreCode = BU & "-" & sDate

    Me.PreCodetxt = DLookup("[Precode]", "[NC_Main_Table]", "[Precode] = '" & Me.PreCode & "'") 'To bring the code recorded if it would exist

    If Me.PreCodetxt = Me.PreCode Then 'To make the comparision between the possible new one and the recorded

    Possible_Consecutive_ID = DMax("[PreCode2]", "[NC_Main_Table]", "[Precode] = '" & Me.PreCode & "'") 'To bring the maximal number recorded of the record..1, 2, 3...

    Me.PreCode2 = Possible_Consecutive_ID + 1 'After 10 I have issues and I don't know why

    Else

    Me.PreCode2 = 1

    End If

    '*************************************
    'CONDITIONS FOR FINAL CODE

    If PreCode2 < 10 Then

    Clave = "NC-" & BU & "-" & sDate & "-" & Zero & Zero & PreCode2

    ElseIf PreCode2 >= 10 And PreCode2 <= 100 Then

    Clave = "NC-" & BU & "-" & sDate & "-" & Zero & PreCode2

    Else

    Clave = "NC-" & BU & "-" & sDate & "-" & PreCode2

    End If

    Me.Code = Clave

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Long will give you billions of numbers, but you show (3) ### as the
    Product1 for a total of 15 spaces (text).
    you are using PreCode as string , which should be a #. THEN you can do math on it.




  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Oh I didn't see that!!

    You were right... I had defined this as text and not as a number...

    Thank you!!!!

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

Similar Threads

  1. Replies: 1
    Last Post: 06-25-2013, 08:57 AM
  2. Replies: 6
    Last Post: 03-21-2012, 07:13 PM
  3. creating an ID number in access
    By gem in forum Access
    Replies: 3
    Last Post: 03-08-2012, 07:07 AM
  4. Replies: 38
    Last Post: 05-21-2010, 11:56 AM
  5. creating automated ticket number
    By speak2des in forum Access
    Replies: 1
    Last Post: 02-25-2010, 11:32 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