|
这个问题之前我也遇到,后面在论坛上找了这个,但不知是出自哪位大神之手了。
Total表加编号前后对比
加编号后
加编号前
‘--------------------------------------------
Public Function AutoNumStr( _
TableName As String, _
FieldName As String, _
Digit As Integer, _
Optional Prefixal As String, _
Optional DateFormat As String)
'自动编号
On Error GoTo ErrorHandler
Dim strPrefixal As String
Dim strTemp As String
strPrefixal = Prefixal
If DateFormat <> "" Then strPrefixal = strPrefixal & Format(Date, DateFormat)
If strPrefixal <> "" Then strTemp = "[" & FieldName & "] Like '" & strPrefixal & "*'"
strTemp = Nz(DMax(FieldName, TableName, strTemp), "0")
strTemp = Val(Mid(strTemp, Len(strPrefixal) + 1)) + 1
strTemp = Format(strTemp, String(Digit, "0"))
AutoNumStr = strPrefixal & strTemp
Done:
Exit Function
ErrorHandler:
MsgBox "错误编号: #" & err & vbCrLf & _
"错误来源: " & err.Source & vbCrLf & _
"错误信息: " & err.Description, vbCritical, "出错"
Resume Done
End Function
'-----------------------------------------------------------------------------
Public Sub AutoNum() '对 Total 表 进行自动编号
Dim rst As Object
CurrentDb().Execute "update Total set 核算部门序号="" where 核算部门序号<>"""
Set rst = CurrentDb.OpenRecordset("Total")
Do Until rst.EOF
rst.Edit
rst!核算部门序号 = AutoNumStr("Total", "核算部门序号", 5, rst!核算部门, "-")
rst.Update
rst.MoveNext
Loop
rst.Close
End Sub
'--------------------------------------------
|
|