尝试了多次尝试。
有一个表单作为搜索表单“frm_Search2017” 其中有几个未绑定的字段,一些文本框,一些日期和一些组合框。
在表单上有一个子表单,当您点击搜索时,它会作为搜索脚本运行并根据输入的数据进行填充。当你不填写任何字段时,它工作得很好。它也适用于日期和时间。所有文本框和一个组合框。
有几个搜索字段工作得很好,但是有几个组合框根本不起作用并产生运行时错误3464错误消息。
下面是OpenedBy,门票号码,开启日期自开始日期至,到期日期,到期日期至&标题字段有效。
我不确定下一步该去哪儿。
This is my search script:
Private Sub Clear_Click()
DoCmd.Close
DoCmd.OpenForm "frm_Search2017"
End Sub
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If OpenedBy
If Nz(Me.openedby) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "pacs_issues.openedby = '" & Me.openedby & "'"
End If
' If Status
If Nz(Me.statusID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "pacs_issues.statusID = '" & Me.statusID & "'"
End If
' if ticket number
If Nz(Me.TSCTicket) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "pacs_issues.[vendorticketID] = '" & Me.[TSCTicket] & "'"
End If
' If deviceID
If Nz(Me.DeviceID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "pacs_issues.deviceID = '" & Me.DeviceID & "'"
End If
' If Priority
If Nz(Me.Priority) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "pacs_issues.priorityID = '" & Me.Priority & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "pacs_issues.[dateopened] >= " & GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "pacs_issues.[dateopened] <= " & GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
' If Due Date From
If IsDate(Me.DueDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "pacs_issues.[dateclosed] >= " & GetDateFilter(Me.DueDateFrom)
ElseIf Nz(Me.DueDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Due Date To
If IsDate(Me.DueDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "pacs_issues.[dateclosed] <= " & GetDateFilter(Me.DueDateTo)
ElseIf Nz(Me.DueDateTo) <> "" Then
strError = cInvalidDateError
End If
' If Title
If Nz(Me.Title) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "pacs_issues.issuedescription Like '*" & Me.Title & "*'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "frm_search_Browse All Issues2017", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.[frm_search_Browse All Issues2017].Form.Filter = strWhere
Me.[frm_search_Browse All Issues2017].Form.FilterOn = True
End If
End Sub
Function GetDateFilter(dtDate As Date) As String
' Date filters must be in MM/DD/YYYY format
GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
End Function