Find查询可能没有结果,所以必须判断一下结果是不是空的
For Each dr2 As Row In Tables("铝窗库存表").Rows
Dim fdr7 As DataRow = DataTables("铝窗库存表").Find("生产年月 <='" & dr2("上月") & "' and 产品名称='" & dr2("产品名称") & "' And 产品颜色='" & dr2("产品颜色") & "'","生产年月 desc")
If fdr7 IsNot Nothing
dr2("边封_上月结存") = fdr7("边封_本月结存")
End If
Next