我重新编写了搜索代码并将其编写为vba代码而不是查询,但现在我遇到了错误,因为它已全部设置完毕。代码如下:
我得到的代码是OBJECT REQUIRED 424,它突出显示
If Me!txtEmpID Is Not Null Then
Private Sub cmdSearch2_Click()
Dim strSQL As String
strSQL = ""
If Me!txtEmpID Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeID] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtEmpName Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeName] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboEEOC Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EEOC] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboGender Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Gender] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtDivision Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Division] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboRR Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Region] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboDD Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[District] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboJobGroupCode Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobGroupCOde] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtCenter Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Center] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtJobD Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobDesc] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboJobGroup Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobGroup] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboFunction Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Function1] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboMtgReadyLvl Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[MeetingReadinessRating] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboMgrReadyLvl Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[ManagerReadinessRating] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtFeedback Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeFeedback] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboDevelopment1 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment1 & " * ') "
End If
If Me!cboDevelopment2 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment2 & " * ') "
End If
If Me!cboDevelopment3 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment3 & " * ') "
End If
If Me!cboDevelopment4 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment4 & " * ') "
End If
If Me!cboDevelopment5 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment5 & " * ') "
End If
If Me!txtJustification Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Justification] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtNotes Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Notes] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboChanged Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Changed] LIKE '*" & Me!txtEmpID & " * ' "
End If
strSQL = "SELECT * FROM [CDData] WHERE " & strSQL
DoCmd.RunSQL strSQL
End Sub
答案 0 :(得分:2)
在If语句中检查null是否有点不同:
If Not IsNull(Me!txtEmpID) Then
等等。