自动编号
来源:互联网 发布:apache干什么用的 编辑:程序博客网 时间:2024/05/19 21:59
'===============================================================================
'-函数名称: autoID
'-功能描述: 自动编号 ,
'-输入参数说明: 参数1:tblname 表名
' 参数2:fldname 字段名
' 参数3:intlength增长号的长度
' 参数4:prefix 前缀(可选参数)
' 参数5:dateformat时间前缀(可选参数)
'-返回参数说明: 可以按时间自增长编号, 如果没有时间就自增长编号
'-使用语法示例: AutoID("型体编号表", "型体编号", 4, "GL")
' AutoID("型体编号表", "型体编号", 4)
' AutoID("型体编号表", "型体编号", 4, "GL","yyyymmdd")
'-参考:
'-使用注意:
'-兼容性: 2000,XP,2003
'-作者: Victor Duane
'-更新日期: 2007-12-5 17:03
'===============================================================================
Function AutoID(tblName As String, fldName As String, intLength As Integer, Optional Prefix As String = "", Optional DateFormat As String = "") As String
'自动编号 , 可以按时间自增长编号, 如果没有时间就自增长编号
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim intDate As Integer
Dim intPrefix As Integer
Dim strDate As String
Dim strToday As String
Dim OldDate As String
'如果DateFormat为空,当天日期为空,否则为当天日期
If Len(DateFormat) = 0 Then
strToday = ""
Else
strToday = Format(Date, DateFormat)
End If
strDate = strToday
intDate = Len(strDate) '取得时间的长度
intPrefix = Len(Prefix) '取得前缀的长度
Set cn = CurrentProject.Connection
Dim strSQL As String
strSQL = "select * from " & tblName & " order by " & fldName
rs.Open tblName, cn, 1, 2
Debug.Print rs.RecordCount
If rs.RecordCount > 0 Then
rs.MoveLast
'取得最大值的时间前缀
OldDate = Nz(Mid$(rs(fldName), intPrefix + 1, intDate), "")
'判断新增的值是否跨时间
If strToday = OldDate Then
AutoID = Prefix & strDate & Format(Val(Right$(rs(fldName), intLength) + 1), String(intLength, "0"))
Else
AutoID = Prefix & strDate & String(intLength - 1, "0") & "1"
End If
Else
AutoID = Prefix & strDate & String(intLength - 1, "0") & "1"
End If
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Function
- 自动编号
- 自动编号
- 自动编号
- 自动编号
- 自动编号
- 自动编号
- 自动编号
- DataGrid的自动编号
- 重新计算自动编号
- access 自动编号复位
- DataGrid实现自动编号
- ORACLE自动编号
- 关于ACCESS自动编号
- oracle 自动编号谈
- 关于oracle自动编号
- GridView自动编号
- 触发器实现自动编号
- oracle自动编号方法
- USB设备驱动程序导读(3)
- USB设备驱动程序导读(4)
- USB设备驱动程序导读(5)
- eclipse中js文件中文问题
- USB设备驱动程序导读(6)
- 自动编号
- oracle SQL中 over 的用法
- USB设备驱动程序导读(7)
- 完美夏天
- 牛人十个月自学C++ 现在做C#开发工作
- USB设备驱动程序导读(8)
- 《J2EE核心模式》(DAO模式)
- USB设备驱动程序导读(9)
- C#接收邮件