我有一个“确定要从查询中显示的条件”的表单。 这是代码 - 工作正是我想要的:
Option Compare Database
Option Explicit
Private Sub Command47_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"
If Not IsNull(Me.Combo26) Then
strWhere = strWhere & "([Responsible Operator] Like ""*" & Me.Combo26 & "*"") AND "
End If
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([DateInitiated] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
End If
If Not IsNull(Me.txtEndDate) Then
strWhere = strWhere & "([DateInitiated] < " & Format(Me.txtEndDate, conJetDate) & ") AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
Private Sub cmdReset_Click()
Dim ctl As Control
For Each ctl In Me.Section(acHeader).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
ctl.Value = Null
Case acCheckBox
ctl.Value = ""
End Select
Next
Me.FilterOn = True
End Sub
Private Sub Exit_Click()
DoCmd.Close
End Sub
Private Sub Review_Click()
Dim carnum As Long
carnum = Me.CARNumber
DoCmd.OpenForm "CARData Form", , , "CARNumber = " & carnum
End Sub
Private Sub PrintPerformance_Click()
DoCmd.OpenReport "Rpt1 Performance", acViewPreview
End Sub
我在表单上创建了一个打印选项,并希望在报表中显示该表单上显示的记录的结果。我通过print选项创建了一个链接到表单的报表,但无法显示该表单的当前结果。报告的实际来源与表单的源查询相同。我猜这不正确 - 如何从表单中提取数据到报告?感谢
答案 0 :(得分:0)
表单的代码似乎构建了一个Filter
字符串并将其应用于表单的记录源。稍后您要打开报告,并将相同的过滤器应用于报告的记录源。如果是这样,请使用表单的Filter
属性作为 WhereCondition 到OpenReport
。
Private Sub PrintPerformance_Click()
DoCmd.OpenReport "Rpt1 Performance", acViewPreview, _
WhereCondition:=Me.Filter
End Sub