试试这样
Dim nd As String
Select Case e.DataCol.Name
Case "单位","单据日期"
If e.DataRow.IsNull("单位") OrElse e.DataRow.IsNull("单据日期") Then
e.DataRow("生产计划ID") = Nothing
Else
Dim max As String
Dim idx As Integer
nd = Year(e.DataRow("单据日期")) '提取年度
Dim dw As String = e.DataRow("单位")
max = e.DataTable.Compute("Max(生产计划ID)","生产计划ID like '" & dw & "-SC" & nd & "%' And [_Identify] <> '"& e.DataRow("_Identify") &"'") '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(Right(max,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("生产计划ID") = dw & "-SC" & nd & Format(idx,"000")
End If
End Select
[此贴子已经被作者于2014-10-12 20:38:54编辑过]