Autonumber Kombinasi ( otomatis acak nomor ) Dari Tgl Sekarang
Buatlah fungsi pada form lalu tambahkan koding di bawah ini.
Public Sub Autonumber_kombinasi()
v_sql = "SELECT RIGHT(NO_BUKTI,3) AS NO_BUKTI FROM TBL_HEAD WHERE LEFT(NO_BUKTI,1)='A' ORDER BY RIGHT(NO_BUKTI,3) DESC"
If reader.HasRows Then
reader.Read()
Return "A" + Mid("000", 1, 3 - (Val(Trim(reader.Item(0).ToString)) + 1).ToString.Length) + (Val(Trim(reader.Item(0).ToString)) + 1).ToString
Else
Return "A001"
End If
'Contoh No Bukti yyyymmdd-xxx : 20120801-001,20120801-002
'Jika Ingin Setiap TAHUN Ganti/Reset Ke 001 Lagi
v_sql = "SELECT RIGHT(NO_BUKTI,3) AS NO_BUKTI FROM TBL_HEAD WHERE YEAR(LEFT(NO_BUKTI,8))=YEAR(GETDATE()) ORDER BY RIGHT(NO_BUKTI,3) DESC"
'Jika Ingin Setiap BULAN Ganti/Reset Ke 001 Lagi
v_sql = "SELECT RIGHT(NO_BUKTI,3) AS NO_BUKTI FROM TBL_HEAD WHERE YEAR(LEFT(NO_BUKTI,8))+MONTH(LEFT(NO_BUKTI,8))=YEAR(GETDATE())+MONTH(GETDATE()) ORDER BY RIGHT(NO_BUKTI,3) DESC"
'Jika Ingin Setiap HARI Ganti/Reset Ke 001 Lagi
v_sql = "SELECT RIGHT(NO_BUKTI,3) AS NO_BUKTI FROM TBL_HEAD WHERE YEAR(LEFT(NO_BUKTI,8))+MONTH(LEFT(NO_BUKTI,8))+DAY(LEFT(NO_BUKTI,8))=YEAR(GETDATE())+MONTH(GETDATE())+DAY(GETDATE()) ORDER BY RIGHT(NO_BUKTI,3) DESC"
If reader.HasRows Then
reader.Read()
Return Format(Now.Date, "yyyyMMdd") + "-" + (Val(Trim(reader.Item(0).ToString)) + 1).ToString
Else
Return Format(Now.Date, "yyyyMMdd") + "-001"
End If
End Sub
Cukup panggil nama fungsi diatas pada form load atau button
Sekian dan terima kasih
0 comments:
Post a Comment