|
Public Function Autonum(Expr As String, Domain As String, Fcode As String, Optional Ln As Integer, Optional Ymd As String) As String
'Expr-必须,自动编号的字段名,Domain-必须,自动编号字段所在表或查询,Fcode-编号前的任意字符或代码,Ln-日期后的递增数字位数,默认1,Ymd-可选,日期格式,默认"yyyymmdd"
Dim a As Integer
Dim b As Integer
Dim c As String
Dim d As Variant
Dim e As String
Dim f As String
If Nz(Ln, 0) < 1 Then
b = 1
Else
b = Ln
End If
If Ymd = "" Then
e = Format(Date, "yyyymmdd")
Else
e = Format(Date, Ymd)
End If
f = "000000000000000000000"
a = DCount(Expr, Domain)
If a = 0 Then
Autonum = Fcode & e & Right(f, b - 1) & 1
Exit Function
Else
d = Val(Right(DMax(Expr, Domain), Len(e) + b))
c = Left(d, Len(e))
If c >= e Then
Autonum = Fcode & d + 1
Else
Autonum = Fcode & e & Right(f, b - 1) & 1
End If
End If
End Function |
|