我有一个连续表单,标题中有多个过滤器,然后单击按钮应用,并过滤下面的表格。 然后,用户可以点击“报告”。按钮,将过滤器的结果放入报告样式,打印输出友好。 我想知道是否有办法在我的报告中作为文本框或标签返回应用的过滤器?
仅供参考,代码为:
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
非常感谢任何输入。
感谢。
答案 0 :(得分:1)
您应该能够通过引用表单中的文本框或标签动态地执行此操作
使用标题=&#34;在此过滤&#34;
为报告添加标签(lblFilter
)
在表单标题中添加标签(lblFilter
)(make Visible = False
) - 相同标题
在你的行之后
Me.Filter = strWhere
添加该行以填充您的隐形标签
lblFilter.Caption = strWhere
然后在Report_Open事件中添加代码:
Me.lblFilter.Caption = Forms("MyFormName").lblFilter.Caption