现在我的表序号是个4位的从左往右第一位是代表哪个区的,后三位是代表这个区的具体内容序号,我想插入数据时候自动生成序号,我该怎么弄呢,用的是adotable。

解决方案 »

  1.   

    我这里有以前做的(vb):
    Public Function get_CoOutDrictionNo(enterdate As Date)
     Dim Label1 As Label
     Dim has As Boolean
     Dim pub_str3, mon As String
     mon = Mid(enterdate, 6, 2)
     pub_str1 = "select chr_CoDirectionID from AST_CoDirection where left(chr_CoDirectionID,5)='M" & Right(Year(enterdate), 2) & "" & "" & mon & "' group by chr_CoDirectionID"
    init_rst
     mod_ast.rst.Open pub_str1, CurrentProject.Connection, adOpenDynamic, adLockBatchOptimistic, adCmdText
     If mod_ast.rst.RecordCount = 0 Then
       get_CoOutDrictionNo = "M" + Right(Year(enterdate), 2) + mon + "001"
       Exit Function
       End If
     mod_ast.rst.MoveLast
     get_CoOutDrictionNo = Left(mod_ast.rst.Fields(0), 5) + Right(Str(Val(Right(Trim(mod_ast.rst.Fields(0)), 3)) + 1001), 3)
     End Function