umv开发平台中的通用编号函数AccHelp_AutoID 在表中记录不按顺序排列的时候会出现问题,取原来旧的编号。如果出现编号问题将
下面的函数保存在一个新建的模块中就可以。
Function AccHelp_AutoID(prefixion As String, IDlength As Integer, tblName As String, fldName As String) As String
On Error GoTo Err_AccHelp_AutoID:
Dim maxID As String '最后的一个编号
Dim I_fixLen As Integer '前缀长度
Dim FormatString as string
I_fixLen = Nz(Len(prefixion))
ForMatString = String(IDlength, "0")
maxID = Nz(DMax("Right([" & fldName & "], " & IDlength & ")", [tblName], "left([" & fldName & "]," & I_fixLen & ")='" & prefixion & "'"), "0") '取对应条件的最大编号
If maxID = "0" Then '如果没有开始编号,则为1
AccHelp_AutoID = prefixion & Format(1, ForMatString)
Else
AccHelp_AutoID = prefixion & Format(Val(maxID) + 1, ForMatString)
End If
Exit_AccHelp_AutoID:
Exit Function
Err_AccHelp_AutoID:
MsgBox Err.Description, vbCritical, "编号错误提示:"
Resume Exit_AccHelp_AutoID:
End Function