如果复选框为假,如何从我的数据库中排除记录?
How do I exlude records from my database if a checkbox is false?
我有这个拆分表单,其中包含一些基于组合框和搜索字段的基本搜索功能。现在我想排除我的复选框 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
现在我想添加这个名为 chk_NonC
的新复选框不合规
当我将 chk_NonC
设置为 true
并按搜索时,我希望我的拆分表单显示所有记录。
当我将 chk_NonC
设置为 false
并按搜索时,我希望我的拆分表单隐藏所有 Non_compliant
为 true
的记录
您可以将其视为我的数据库的隐藏功能。如果我将此复选框设置为 false,则隐藏所有不合规设置为 true 的记录。
请注意,函数 SearchCriteria
是在组合框的 OnChange 事件上调用的,或者是通过单击拆分表单顶部的搜索图标调用的。
只需遵循为其他控件定义的相同流程。
为合规性创建字符串部分并将其附加到 sql 脚本的其余部分。
Dim strCompliant As String
strCompliant = IIf(Me.chk_NonC,"[Non_compliant]=True","[Non_compliant]=False")
strCriteria = Customer & " And " [...] & " And " & strCompliant
请记住,strCriteria
中的 " And "
连接之间需要空格。
我有这个拆分表单,其中包含一些基于组合框和搜索字段的基本搜索功能。现在我想排除我的复选框 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
现在我想添加这个名为 chk_NonC
当我将 chk_NonC
设置为 true
并按搜索时,我希望我的拆分表单显示所有记录。
当我将 chk_NonC
设置为 false
并按搜索时,我希望我的拆分表单隐藏所有 Non_compliant
为 true
您可以将其视为我的数据库的隐藏功能。如果我将此复选框设置为 false,则隐藏所有不合规设置为 true 的记录。
请注意,函数 SearchCriteria
是在组合框的 OnChange 事件上调用的,或者是通过单击拆分表单顶部的搜索图标调用的。
只需遵循为其他控件定义的相同流程。
为合规性创建字符串部分并将其附加到 sql 脚本的其余部分。
Dim strCompliant As String
strCompliant = IIf(Me.chk_NonC,"[Non_compliant]=True","[Non_compliant]=False")
strCriteria = Customer & " And " [...] & " And " & strCompliant
请记住,strCriteria
中的 " And "
连接之间需要空格。