日期:2014-05-16  浏览次数:21098 次

access不同界面自动单号问题
wangtiecheng老师:如果在两个或三个不同界输入单号存储到一个表中,如:PJ070911001   PJ070911002       CP070911001   CP070911002         PG070911001     PG070911002     这样可分别在不同界面有序做自动单号吗?

这是以前一个界面的自动单号:
Private   Sub   Form_Load()
        Me.流程单号   =   GetBillNumber()
End   Sub

Public   Function   GetBillNumber()   As   String
        Dim   S   As   String
       
        S   =   Nz(DMax( "流程单号 ",   "表名 "),   " ")
       
        If   Left(S,   8)   <>   Format(Date,   "yyyymmdd ")   Or   S   =   " "   Then
                S   =   Format(Date,   "yyyymmdd ")   &   "001 "
        Else
                S   =   Left(S,   8)   &   Right( "000 "   &   Val(Right(S,   3))   +   1,   3)
        End   If
       
        GetBillNumber   =   S
End   Function
谢谢!

------解决方案--------------------
Private Sub Form_Load()
Me.流程单号 = GetBillNumber( "PJ ")
End Sub

Public Function GetBillNumber(strType as String) As String
Dim S As String

S = Nz(DMax( "流程单号 ", "表名 ", "left(流程单号,2)= ' " & strType & " ' "), " ")

If Left(S, 8) <> strType & Format(Date, "yymmdd ") Or S = " " Then
S = strType & Format(Date, "yymmdd ") & "001 "
Else
S = Left(S, 8) & Right( "000 " & Val(Right(S, 3)) + 1, 3)
End If

GetBillNumber = S
End Function