自定义自动编号函数-吕生
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


自定义自动编号函数

发表时间:2017/8/28 11:59:05 评论(0) 浏览(16892)  评论 | 加入收藏 | 复制
   
摘 要:自定义自动编号函数
正 文:

查找资料找到的自定义自动编号函数

感谢原作者

我仅仅是搬运工


自定义自动编号函数
'========================================================================================
'-函 数 名: AutoNumber
'-函数用途: 设置自定义自动编号
'-参数说明: 参数1:Prefixal----编号前缀
'- 参数2:Digit----编号位数
'- 参数3:FieldName----自动编号所在字段名
'- 参数4:TableName----自动编号所在表名
'-返回参数: 调用成功返回将要向新记录中添加的最大编号,调用失败返回空字符串""
'-调用方法: 在窗体的Current(当前)事件中调用
'-调用示例: Me.自动编号.DefautValue = AutoNumber("[审]",7,"自动编号","审核表")
'-使用注意: 表中的自动编号字段数据类型要设成文本型
'-作 者: 红尘如烟
'-
'=============================================================================================
Function AutoNumber(Prefixal As String, Digit As Integer, FieldName As String, TableName As String) As String
On Error GoTo AutoNumber_Err


Dim strMaxID As Long
Dim strNumberFormat As String
Dim i As Integer


strMaxID = Nz(DMax("Right( " & FieldName & "," & Digit & ")", TableName)) + 1
For i = 1 To Digit
strNumberFormat = strNumberFormat & "0"
Next
AutoNumber = """" & Prefixal & Format(strMaxID, strNumberFormat) & """"


AutoNumber_Exit:
Exit Function


AutoNumber_Err:
AutoNumber = ""
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "自动编号出错"
Resume AutoNumber_Exit
End Function


Access软件网交流QQ群(群号:198465573)
 
 相关文章
自动编号函数AutoID  【Victor Duane  2008/8/20】
再谈自动编号函数AutoNum()可以检测断号...使断号重续.....  【chenlugen  2008/8/31】
类似含有年月日的自动编号函数  【风行  2011/5/25】
可带前缀和后缀的自动编号函数  【wsl  2012/2/8】
高效的年月日的自动编号函数  【LiShiping  2012/8/18】
高效的自动编号函数  【网行者  2013/1/18】
常见问答
技术分类
相关资源
文章搜索
关于作者

吕生

文章分类

文章存档

友情链接