Click here to Skip to main content
15,885,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to implement in code ..
i was tried but still increase when date change...
i'm still confusing ...
Autonumber ---

CODE DATE NUMBER
PL-18/07/2017-0001
PL-18/07/2017-0002
PL-18/07/2017-0003
PL-19/07/2017-0001 -----> Date Change the number back to "0001"
PL-19/07/2017-0002
PL-19/07/2017-0003

please help me guys..
thanks !!

What I have tried:

Call koneksi()
        sql = "select * from penjualan order by no_faktur desc"
        cmd = New OleDbCommand(sql, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If Not dr.HasRows Then
            penfaktur.Text = "PL" + Format(Now, "ddMMyyyy") + "0001"
        Else
            penfaktur.Text = Val(Microsoft.VisualBasic.Mid(dr.Item("no_faktur").ToString, 11, 4)) + 1
        End If
        If Len(penfaktur.Text) = 1 Then
            penfaktur.Text = "PL" + Format(Now, "ddMMyyyy") + "000" & penfaktur.Text & ""
        ElseIf Len(penfaktur.Text) = 2 Then
            penfaktur.Text = "PL" + Format(Now, "ddMMyyyy") + "00" & penfaktur.Text & ""
        ElseIf Len(penfaktur.Text) = 3 Then
            penfaktur.Text = "PL" + Format(Now, "ddMMyyyy") + "0" & penfaktur.Text & ""
        ElseIf Len(penfaktur.Text) = 4 Then
            penfaktur.Text = "PL" + Format(Now, "ddMMyyyy") + "" & penfaktur.Text & ""
        End If
Posted
Updated 19-Jul-17 16:05pm
v2
Comments
Bernhard Hiller 18-Jul-17 3:20am    
Your code will fail when 2 (or more users) save data to the database at the same time. The generation of that number must be delegated to the database.
Khabibb Mubarakk 18-Jul-17 7:17am    
really.. can you tell me with code ..
Ralf Meier 18-Jul-17 3:39am    
You have allready got the answer to your question here :
https://www.codeproject.com/Questions/1196103/Automatic-number-with-date-format

Why didn't you followed the Suggestion ?
The only way to detect if the date has changed is to compared it with the Date from the entry before - if they are different you could begin again by 1 with your numbers ...
Khabibb Mubarakk 18-Jul-17 7:14am    
because i'm newbie and i need complete code to understand..
Ralf Meier 18-Jul-17 8:07am    
OK ... in your code-sample you read the last number +1 into 'penfaktur.Text'.
As I understand your code dr.Item("no_faktur") contains the date and the number from the last saved entry - so ... if you are able to extract the number from it ... why don't you are able to extract the date-part from it and compare it with Now ? If both Dates are un-equal you do the same as when dr has now rows - where is the Problem. That has nothing in common with Newbie or not-Newbie ... that means "think about"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900