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