我有一个 MS Access 表单,用户可以在其中选择最多四个条件来过滤报告返回的记录。在 VBA 中,我试图根据用户选择过滤的字段(如果有)动态构建过滤器字符串。下面的代码给了我一个“Block If without End If”错误。我在这里做错了什么?
If (IsNull(frm!employee) = False) Then
strFilter = "Trainee_First_Name + ' ' + Trainee_Last_Name = '" & frm!employee & "'"
If IsNull(frm!sop) = False Then
strFilter = strFilter + " AND sop_number = '" & frm!sop & "'"""
End If
If IsNull(frm!revision) = False Then
strFilter = strFilter + " AND revision_number = '" & frm!revision & "'"
End If
If IsNull(frm!dept) = False Then
strFilter = strFilter + " AND department = '" & frm!dept & "'"
End If
Else
If (IsNull(frm!sop) = False) Then
strFilter = "sop_number = '" & frm!sop & "'"
If (IsNull(frm!employee) = False) Then
strFilter = "Trainee_First_Name + ' ' + Trainee_Last_Name = '" & frm!employee & "'"
End If
If IsNull(frm!revision) = False Then
strFilter = strFilter + " AND revision_number = '" & frm!revision & "'"
End If
If IsNull(frm!dept) = False Then
strFilter = strFilter + " AND department = '" & frm!dept & "'"
End If
Else
If (IsNull(frm!revision) = False) Then
strFilter = "revision_number = '" & frm!revision & "'"
If (IsNull(frm!employee) = False) Then
strFilter = " AND Trainee_First_Name + ' ' + Trainee_Last_Name = '" & frm!employee & "'"
End If
If IsNull(frm!sop) = False Then
strFilter = strFilter + " AND sop_number = '" & frm!sop & "'"""
End If
If IsNull(frm!dept) = False Then
strFilter = strFilter + " AND department = '" & frm!dept & "'"
End If
Else
If IsNull(frm!dept) = False Then
strFilter = "department = '" & frm!dept & "'"
If (IsNull(frm!employee) = False) Then
strFilter = " AND Trainee_First_Name + ' ' + Trainee_Last_Name = '" & frm!employee & "'"
End If
If IsNull(frm!sop) = False Then
strFilter = strFilter + " AND sop_number = '" & frm!sop & "'"""
End If
If IsNull(frm!revision) = False Then
strFilter = strFilter + " AND revision_number = '" & frm!revision & "'"
End If
End If
您可以给我任何改进此代码的建议将不胜感激。