代码要改成这样
Dim filter As String = "年度 = '" & Date.Today.year & "'"
If r("企业名称") = Nothing Then
filter &= " and 企业名称 is null"
Else
filter &= " and 企业名称 = '" & r("企业名称") & "'"
End If
If r("部门") = Nothing Then
filter &= " and 部门 is null"
else
filter &= " and 部门 = '" & r("部门") & "'"
End If
If r("岗位设置") = Nothing Then
filter &= " and 岗位设置 is null"
Else
filter &= " and 岗位设置 = '" & r("岗位设置") & "'"
End If
msgbox(filter)
Dim nr As DataRow = DataTables("年度安全目标").Find(filter)