调试
Select e.DataCol.Name
Case "编号"
If e.DataRow.IsNull("编号") Then
e.DataRow("培训记录编号") = Nothing
Else
Dim bh As String = e.DataRow("编号")
msgbox("bh=" & bh)
If e.DataRow("培训记录编号").StartsWith(bh & “_”) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(培训记录编号)","编号 = '" & bh & "' And [_identify] <> " & e.DataRow("_identify")) '取得该类别的最大编号
msgbox("max =" & max )
If max > "" Then '如果存在最大编号
msgbox("Substring=" & max.Substring(max.length - 3))
idx = CInt(max.Substring(max.length - 3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
msgbox("idx =" & idx )
e.DataRow("培训记录编号") = bh & "_" & Format(idx,"000")
End If
End If
End Select