这样试试,我测试可以:
'日期转换
Dim rq As Date = Today()
'删除加班补休填报所有行
DataTables("在册名单").DeleteFor("[编号] Is Not Null ")
MainTable= Tables("在册名单")
'填充编号
Dim f As New Filler
f.SourceTable = DataTables("名册清单") '指定数据来源
f.SourceCols = "编号,入监日期,离监日期" '指定数据来源列
f.DataTable = DataTables("在册名单") '指定数据接收表
f.DataCols = "编号,入监日期,离监日期" '指定数据接收列
f.Filter = "入监日期 <= '" & rq & "' And 离监日期 > '" & rq & "'"
f.Fill() '填充数据
For Each dr As DataRow In DataTables("在册名单").DataRows
Dim pr As DataRow
If dr.IsNull("编号") Then
dr("单位") = Nothing
Else
pr = DataTables("变动日期").Find("编号 = '' ")
pr = DataTables("变动日期").Find("编号 = '" & dr("编号") & _
"' And 变动日期 <= '" & rq & "'","变动日期 Desc")
If pr IsNot Nothing Then
dr("监区") = pr("监区")
dr("单位") = pr("单位")
dr("变动日期") = pr("变动日期")
End If
End If
Next
Tables("在册名单").Sort = "单位,编号"
Tables("在册名单").AutoSizeCols()
Tables("在册名单").Cols.Frozen = 4
Tables("在册名单").ListMode = True
With Tables("在册名单") '返回最末行
.Position = .Rows.Count - 1
End With