我有這個帶有一些基于組合框和搜索欄位的基本搜索功能的拆分表單。現在我想排除我的復選框chk_NonC= false的記錄。
我目前用來過濾我的記錄源的 VBA 代碼qry_Administration:
Function SearchCriteria()
Dim Customer, CustomerLocation, CustomerLocationPlace, ExecutionDate, Material As String
Dim Intern, Extern As String
Dim task, strCriteria As String
If Me.chk_AuditEX = True Then
Extern = "[AuditEX] = " & Me.chk_AuditEX
Else
Extern = "[AuditEX] like '*'"
End If
If Me.chk_AuditIN = True Then
Intern = "[AuditIN] = " & Me.chk_AuditIN
Else
Intern = "[AuditIN] like '*'"
End If
If IsNull(Me.cbo_CustomerLocations) Then
CustomerLocation = "[CustomerLocationID] like '*'"
CustomerLocationPlace = "[LocationCompanyPlace] like '*'"
Else
CustomerLocation = "[LocationCompanyName] = '" & Me.cbo_CustomerLocations.Column(0) & "'"
CustomerLocationPlace = "[LocationCompanyPlace] = '" & Me.cbo_CustomerLocations.Column(1) & "'"
End If
If IsNull(Me.cbo_Customers) Then
Customer = "[CustomerID] like '*'"
Else
Customer = "[CustomerID] = " & Me.cbo_Customers
End If
If IsNull(Me.txt_ExecutionDateTo) Then
ExecutionDate = "[ExecutionDate] like '*'"
Else
If IsNull(Me.txt_ExecutionDateFrom) Then
ExecutionDate = "[ExecutionDate] like '" & Me.txt_ExecutionDateTo & "'"
Else
ExecutionDate = "([ExecutionDate] >= #" & Format(Me.txt_ExecutionDateFrom, "mm/dd/yyyy") & "# And [ExecutionDate] <= #" & Format(Me.txt_ExecutionDateTo, "mm/dd/yyyy") & "#)"
End If
End If
If IsNull(Me.cbo_Material) Or Me.cbo_Material = "" Then
Material = "[MaterialID] like '*'"
ElseIf Me.cbo_Material = 6 Then
Material = "[MaterialID] in (" & TempVars!tempMaterial & ")"
Else
Material = "([MaterialID] = " & Me.cbo_Material & ")"
End If
strCriteria = Customer & "And" & CustomerLocation & "And" & CustomerLocationPlace & "And" & _
& ExecutionDate & Material & "And" & Extern & "And" & Intern
task = "Select * from qry_Administration where (" & strCriteria & ") order by ExecutionDate DESC"
Debug.Print (task)
Me.Form.RecordSource = task
Me.Form.Requery
End Function
現在我想添加這個名為 Non-Compliant 的新復選框 chk_NonC
當我設定chk_NonC為true并按搜索時,我希望我的拆分表單顯示所有記錄。
當我設定chk_NonC到false,然后按搜索我希望我的分割形式來隱藏所有記錄Non_compliant是true
您可以將其視為我的資料庫的隱藏功能。如果我將此復選框設定為 false,則隱藏所有不合規設定為 true 的記錄。
請注意,該函式SearchCriteria是在組合框的 OnChange 事件上呼叫的,或者通過單擊我的拆分表單頂部的搜索圖示來呼叫。
uj5u.com熱心網友回復:
只需遵循為其他控制元件定義的相同流程即可。
創建符合性的字串部分并將其附加到 sql 腳本的其余部分。
Dim strCompliant As String
strCompliant = IIf(Me.chk_NonC,"[Non_compliant]=True","[Non_compliant]=False")
strCriteria = Customer & " And " [...] & " And " & strCompliant
請記住,您需要" And "在strCriteria.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/359367.html
上一篇:條件運算式中的資料型別沖突
下一篇:訪問-未觸發滑鼠按下事件
