我在每个窗体中都写了怎么一段程序(不同处就是操作的表名不同!)
Private Sub AutoNumber() '自动编号 Dim StrRyhtID As String Dim UserAddit As New ADODB.Recordset StrRyhtID = "select 人员合同id from citdcuser.其它险种 order by 人员合同id" UserAddit.Open StrRyhtID, CLDB.Conn, adOpenKeyset, adLockBatchOptimistic If UserAddit.RecordCount > 0 Then UserAddit.MoveLast '到最后 If UserAddit.Fields("人员合同id") <> "" Then txtRyhtID = "Other" & Format(Val(Right(UserAddit.Fields("人员合同id"), 6)) + 1, "000000") Else txtRyhtID = "Other000001" End If End Sub
我现在想将该程序转变为系统内共用的. Public function AutoNumber(TableName as string,A as string) as string '自动编号 Dim UserAddit As New ADODB.Recordset Dim StrID as string StrID = "select 人员合同id from "&A & " order by 人员合同id" UserAddit.Open StrID, CLDB.Conn, adOpenKeyset, adLockBatchOptimistic If UserAddit.RecordCount > 0 Then UserAddit.MoveLast '到最后 If UserAddit.Fields("人员合同id") <> "" Then AutoNumber= "Other" & Format(Val(Right(UserAddit.Fields("人员合同id"), 6)) + 1, "000000") Else AutoNumber = Tablename&"000001" End If End function
以后在每个窗体中调用的时候我写 Dim xx01 as string,xx02..... xx01="DangAn" xx02="citdcuser.其它险种"
TEXT02.TEXT=AutoNumber(XX01,XX02)
1.是不是这样一来TEXT02就得到了我需要表的ID编号. 2.对于这段程序如果可行,那么我应写到标准模块还是类模块中呢!