If User.Group = "行政" Or User.name = "开发者"
If CurrentTable.name.contains("模具保养")
For Each r As Row In Tables("生产模数统计").rows
Dim NY As String = r("年") & r("月")
If NY.length = 5
NY = r("年") & "0" & r("月")
Else
NY = r("年") & r("月")
End If
If r("模具型号") = ""
Else
For Each dr As DataRow In DataTables("模具保养").DataRows
If dr("年月") = NY And dr("模具型号") = r("模具型号")
dr("本月生产") = r("生产模数")
Exit For
End If
Next
End If
Next
End If
End If
以上为原代码是可以正常运行的,但是,如果“模具保养”没有的“模具型号”而“生产模数统计”有的“模具型号”则不会自动添加到“模具保养”这个数据表去。
===========================
我改成如下代码,但是运行起来会有问题:“模具保养”有的“模具型号”而且“生产模数统计”也有的“模具型号”,会自动再添加一次到“模具保养”这个数据表去。请帮我修改一下下面的代码,谢谢。
If User.Group = "行政" Or User.name = "开发者"
If CurrentTable.name.contains("模具保养")
For Each r As Row In Tables("生产模数统计").rows
Dim NY As String = r("年") & r("月")
If NY.length = 5
NY = r("年") & "0" & r("月")
Else
NY = r("年") & r("月")
End If
If r("模具型号") = ""
Else
For Each dr As DataRow In DataTables("模具保养").DataRows
If dr("年月") = NY
if dr("模具型号") = r("模具型号")
dr("本月生产") = r("生产模数")
Exit For
else
Dim dr1 As DataRow
dr1 = DataTables("模具保养").AddNew()
dr1("模具型号") = r("模具型号")
dr1("本月生产") = r("生产模数")
Exit For
End If
end if
Next
End If
Next
End If
End If