maidinhdan > 30-05-17, 11:55 PM
'---------------------------------------------------------------------------------------
' Procedure : LaySTT2
' Author : HenDan
' Date : 5/30/2017
' Purpose : So thu tu tang dan reset moi thang, Khong dua vao query ma truy van truc tiep bang ham Dlast
'---------------------------------------------------------------------------------------
' Cu phap: LaySTT2("tblPhieuNhap", "ID", "X")
Function LaySTT2(TenTable As String, TenCotSTT As String, KyTyCanChen As String) As String
On Error Resume Next
Dim SoTD As Double, s As Double
Dim SoMax As String, SoNext As String
Dim yy As String, mm As String, dd As String
yy = Format(Year(Date), "0000")
mm = Format(Month(Date), "00")
dd = Format(Day(Date), "00")
'SoMax = DLast("[ID]", "[tblPHIEUNHAP]", "Mid([ID], 2, 6)='" & yy & mm & "'") ' Lay mau tin cuoi cung duoc tao
SoMax = DLast(TenCotSTT, TenTable, "Mid([" & TenCotSTT & "], 2, 6)='" & yy & mm & "'") ' Lay mau tin cuoi cung duoc tao
SoMax = Right(SoMax, 4) ' Lay STT 4 ky tu cuoi
s = Val(SoMax) ' Chuyen chuoi thanh so
If IsNull(s) Then
SoTD = 1
Else
SoTD = s + 1
End If
SoNext = Format(SoTD, "0000") ' Dinh dang kieu 4 ky tu de hien thi, Nhu vay So thu tu lon nhat se la 9999
LaySTT2 = KyTyCanChen & yy & mm & dd & SoNext
End Function