|
QUOTE:
Public Function ZDYBH(StrTable As String, StrField As String, StrBH As String, Optional FDay As String = "YYMMDD", Optional ILen As Integer = 3, Optional B As Boolean = False) As String
'==================================================================
'功能: 自定义用户编号,带断号检测功能
'格式: "XXX"-"日期格式 "-"0000"
' StrTable 为任意表名称
' StrField 为任意字段名称
' StrBH 编码类型 , 可自义任意格式
' FDay 日期格式 默认日期格式为:YYMMDD",其他符合FORMAT格式的如 YYYYMM,YYYY,YYYYMMDD
' ILen 为数字格式化长度 , 默认长度为3 代表 000 格式
' B 为是否要检测断号 ,默认为FALSE 不检测
'用法: ZDYBH("产量表", "产量ID", "LDH")
' ZDYBH("产量表", "产量ID", Me.Combo1)
' ZDYBH("产量表", "产量ID", Me.Combo1, "YYYY")
' ZDYBH("产量表", "产量ID", Me.Combo1, , 4, True)
'作者: andymark
' QQ : 42503577 , ewang11@163.com
'日期: 2008-4-2
'===============================================================
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Dim Str As String
Dim Num As Integer
Dim TNum As Integer
Dim StrWhere As String
Dim StrOrderWhere As String
Set Conn = CurrentProject.Connection
Str = StrBH & "-" & Format(Now(), "" & FDay & "") & "-"
StrWhere = "select " & StrField & " from " & StrTable & " where " & StrField & " like '" & Str & "%'"
StrOrderWhere = StrWhere & " Order by " & StrField & " DESC"
Rs.Open StrOrderWhere, Conn, adOpenKeyset, adLockOptimistic
If Rs.EOF Then
Num = 0
Else
Num = Right(Rs.Fields("" & StrField & ""), ILen)
If B = True Then
If CInt(Num) <> Rs.Fields.Count Then
Rs.Close
Rs.Open StrWhere, Conn, adOpenKeyset, adLockOptimistic
Num = 0
Do While Not Rs.EOF
TNum = CInt(Right(Rs.Fields("" & StrField & ""), ILen))
If TNum - Num = 1 Then
Num = TNum
Else
Exit Do
End If
Rs.MoveNext
Loop
End If
End If
End If
ZDYBH = StrBH & "-" & Format(Now(), "" & FDay & "") & "-" & Format(Num + 1, String(ILen, "0"))
Set Rs = Nothing
Set Conn = Nothing
End Function
|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )
GMT+8, 2024-12-27 13:06 , Processed in 0.058020 second(s), 14 queries .
Powered by Discuz! X3.3
© 2001-2017 Comsenz Inc.