Access 2010 VBA 过滤器 --> 如何在报表中显示过滤器字符串 textbox/label
Access 2010 VBA Filter --> How to display the filter string in a report textbox/label
我有一个连续表单,它在 header 中有多个过滤器,然后单击按钮应用这些过滤器,并过滤下面的 table。
然后用户可以单击 'Report' 按钮,该按钮会将过滤器的结果放入报告样式中,print-out 友好。
我想知道是否有办法 return 应用过滤器,作为我报告中的文本框或标签?
仅供参考,代码是:
Private Sub frm_Filter_Click()
Dim strWhere As String
Dim lngLen As Long
If Not IsNull(Me.cmbCategory) Then
strWhere = strWhere & "([Category] = """ & Me.cmbCategory & """) AND "
End If
If Not IsNull(Me.cmbStage) Then
strWhere = strWhere & "([Stage] = """ & Me.cmbStage & """) AND "
End If
If Not IsNull(Me.cmbImpact) Then
strWhere = strWhere & "([Impact] = """ & Me.cmbImpact & """) AND "
End If
If Not IsNull(Me.cmbStatus) Then
strWhere = strWhere & "([Status] = """ & Me.cmbStatus & """) AND "
End If
If Not IsNull(Me.cmbOwner) Then
strWhere = strWhere & "([Owner] = """ & Me.cmbOwner & """) AND "
End If
If Not IsNull(Me.cmbChangeType) Then
strWhere = strWhere & "([ChangeType] = """ & Me.cmbChangeType & """) AND "
End If
If Not IsNull(Me.txtOBR) Then
strWhere = strWhere & "([tbl_Main.OBR] Like ""*" & Me.txtOBR & "*"") AND "
End If
If Not IsNull(Me.txtRaisedBy) Then
strWhere = strWhere & "([tbl_Main.RaisedBy] Like ""*" & Me.txtRaisedBy & "*"") AND "
End If
If Not IsNull(Me.txtApplication) Then
strWhere = strWhere & "([tbl_Main.Application] Like ""*" & Me.txtApplication & "*"") AND "
End If
If Not IsNull(Me.txtSearch) Then
strWhere = strWhere & "(tbl_Main.Description Like '*" & Me.txtSearch & "*' OR tbl_Main.LessonsLearnt Like '*" & Me.txtSearch & "*' OR tbl_Main.RecommendedAction Like '*" & Me.txtSearch & "*') AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No Criteria Selected", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
非常感谢任何意见。
谢谢。
您应该能够通过引用表单中的文本框或标签动态地完成此操作
为您的报告添加标签 (lblFilter
),标题 = "Filter Here"
在您的表单中添加标签 (lblFilter
) header (使 Visible = False
) - 相同的标题
就在你的行之后
Me.Filter = strWhere
添加行以填充您的不可见标签
lblFilter.Caption = strWhere
然后在您的 Report_Open 活动中添加代码:
Me.lblFilter.Caption = Forms("MyFormName").lblFilter.Caption
我有一个连续表单,它在 header 中有多个过滤器,然后单击按钮应用这些过滤器,并过滤下面的 table。 然后用户可以单击 'Report' 按钮,该按钮会将过滤器的结果放入报告样式中,print-out 友好。 我想知道是否有办法 return 应用过滤器,作为我报告中的文本框或标签?
仅供参考,代码是:
Private Sub frm_Filter_Click()
Dim strWhere As String
Dim lngLen As Long
If Not IsNull(Me.cmbCategory) Then
strWhere = strWhere & "([Category] = """ & Me.cmbCategory & """) AND "
End If
If Not IsNull(Me.cmbStage) Then
strWhere = strWhere & "([Stage] = """ & Me.cmbStage & """) AND "
End If
If Not IsNull(Me.cmbImpact) Then
strWhere = strWhere & "([Impact] = """ & Me.cmbImpact & """) AND "
End If
If Not IsNull(Me.cmbStatus) Then
strWhere = strWhere & "([Status] = """ & Me.cmbStatus & """) AND "
End If
If Not IsNull(Me.cmbOwner) Then
strWhere = strWhere & "([Owner] = """ & Me.cmbOwner & """) AND "
End If
If Not IsNull(Me.cmbChangeType) Then
strWhere = strWhere & "([ChangeType] = """ & Me.cmbChangeType & """) AND "
End If
If Not IsNull(Me.txtOBR) Then
strWhere = strWhere & "([tbl_Main.OBR] Like ""*" & Me.txtOBR & "*"") AND "
End If
If Not IsNull(Me.txtRaisedBy) Then
strWhere = strWhere & "([tbl_Main.RaisedBy] Like ""*" & Me.txtRaisedBy & "*"") AND "
End If
If Not IsNull(Me.txtApplication) Then
strWhere = strWhere & "([tbl_Main.Application] Like ""*" & Me.txtApplication & "*"") AND "
End If
If Not IsNull(Me.txtSearch) Then
strWhere = strWhere & "(tbl_Main.Description Like '*" & Me.txtSearch & "*' OR tbl_Main.LessonsLearnt Like '*" & Me.txtSearch & "*' OR tbl_Main.RecommendedAction Like '*" & Me.txtSearch & "*') AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No Criteria Selected", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
非常感谢任何意见。
谢谢。
您应该能够通过引用表单中的文本框或标签动态地完成此操作
为您的报告添加标签 (lblFilter
),标题 = "Filter Here"
在您的表单中添加标签 (lblFilter
) header (使 Visible = False
) - 相同的标题
就在你的行之后
Me.Filter = strWhere
添加行以填充您的不可见标签
lblFilter.Caption = strWhere
然后在您的 Report_Open 活动中添加代码:
Me.lblFilter.Caption = Forms("MyFormName").lblFilter.Caption