以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  仍然关于自动编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=93329)

--  作者:nazi3729
--  发布时间:2016/11/25 12:03:00
--  仍然关于自动编号
“入库日期”是日期类型的日期列,“入库单号”想根据“入库日期”自动生成一个不重复的序列号,在表事件的DataColChanged里面写

If e.DataCol.Name = "入库日期" Then

    If e.DataRow.IsNull("入库日期") Then

        e.DataRow("入库单号") = Nothing

    Else

        Dim bh As String = Format(e.DataRow("入库日期"),"yyyyMMdd") \'取得编号的8位前缀

        If e.DataRow("入库单号").StartsWith(bh) = False \'如果编号的前8位不符

            Dim max As String

            Dim idx As Integer

            max = e.DataTable.Compute("Max(入库单号)","入库日期 = #" & e.DataRow("入库日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号

            If max > "" Then \'如果存在最大编号

                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1

            Else

                idx = 1 \'否则顺序号等于1

            End If

            e.DataRow("入库单号") = bh & "-" & Format(idx,"000")

        End If

    End If

End If

但是“入库编号”又分不同的部门,如何能够在编号前加上一个字母什么的?以区分?或者按照另外一种自动编号的方式来实现?只要不重复。


--  作者:有点蓝
--  发布时间:2016/11/25 12:10:00
--  
参考:http://www.foxtable.com/webhelp/scr/2403.htm

看例4