Dim dr As Row=Tables("产品销售").addnew
Dim bh As String ="XS" & Format(Date.Today ,"yyyyMMdd") '取得编号的8位前缀
Dim max As String
Dim idx As Integer
max = DataTables("产品销售").sqlCompute("Max(销售单号)","销售日期 >= '" & Date.Today & "' and 销售日期 <= '" & Date.Today.AddDays(1) & "' and 销售单号 like 'XS*' " ) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(10,4)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
dr("销售单号") = bh & Format(idx,"0000")