|
首先思路是单号不能重复,可新增一个‘新增’按钮,完成自动单号(单号永不重复):
Call 数据库名
sql = "select distinct 编号 from In_Info where 编号 like " & "'%" & "B" & VBA.Format(VBA.Date, "yyyymm") & "%'"
RST.Open sql, CNN, adOpenKeyset, adLockReadOnly
If RST.RecordCount = 0 Then
Me.Range("j3").Value = "X" & VBA.Format(VBA.Date, "yyyymm") & VBA.Format(1, "000")
Else
Set RST = Nothing
sql = "select distinct 编号 from In_Info where 编号 like " & "'%" & "X" & VBA.Format(VBA.Date, "yyyymm") & "%' order by 编号 desc"
RST.Open sql, CNN, adOpenKeyset, adLockReadOnly
Me.Range("J3").Value = "X" & VBA.Format(VBA.Date, "yyyymm") & VBA.Format(VBA.Val(VBA.Right(RST.Fields("编号"), 3)) + 1, "000 ")
End If
Call 关闭数据库 |
|