老师,增加条件判断代码后(红色部分),后面(ELSE后)的代码就不是原来合并增加到目标表了,而按行添加(来源表有多少行就添加多少行)的目标表了。条件语句有错?测试情况是条件语句没有错了,当目标表已经有相同记录的行时,就不再执后面的了
With Tables("提取工艺")
For Each r As Row In Tables("提取工艺").Rows
If r("选择") = True Then
If DataTables("提取产品成本表").Find("产品批号 = '" & r("产品批号") & "'AND 存货编码 = '" & r("存货编码") & "'") IsNot Nothing Then
Messagebox.Show("提取产品成本表已经存在相同批号且编码相同的记录","提示", MessageBoxButtons.YesNo,MessageBoxIcon.Information)
Return '那么返回
Else
If .Rows.Count > 0 Then
Dim dr As Row = .Rows( .TopPosition )
Dim drnew As Row = Tables("提取产品成本表").AddNew
drnew("存货名称") = dr("产品名称")
drnew("存货编码") = dr("产品编码")
drnew("产品批号") = dr("产品批号")
drnew("产品批次") = dr("产品批次")
'其它字段赋值
Dim acount As Double
For i As Integer = .TopPosition To .BottomPosition
acount += .Rows(i)("金额")
Next
drnew("流转金额") = acount
End If
MainTable = Tables("提取产品成本表")
End If
End If
Next
End With