希望下表中的表格编号对应的物资编号可以自动生成,
表格编号 物资编号
201704-001
1
201704-001
2
201704-001
3
201704-002
1
201704-002
2
请问要如何修改以下代码,多谢!
If e.DataCol.Name = "表格编号" Then
If e.DataRow.IsNull("表格编号") Then
e.DataRow("物资编号") = Nothing
Else
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(物资编号)","物资编号= #"& "# And [_Identify] <> " & e.DataRow("_Identify"))
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(3,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("物资编号") = Format(idx,"000")
End If
End If