1

我有一个“确定条件”从查询中显示的表单。这是代码 - 就像我想要的那样工作:

    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

我在表单上创建了一个打印选项,并希望在报告中显示该表单上显示的记录结果。我通过打印选项创建了一个链接到表单的报告,但无法让它显示表单的当前结果。报告的实际来源与表单的来源查询相同。我猜这是不正确的 - 如何从表单中提取数据到报告中?谢谢

4

1 回答 1

0

似乎表单的代码构建了一个Filter字符串并将其应用于表单的记录源。稍后,您希望使用应用于报表记录源的相同过滤器打开报表。如果是这样,请将表单的Filter属性用作WhereCondition to OpenReport

Private Sub PrintPerformance_Click()
    DoCmd.OpenReport "Rpt1 Performance", acViewPreview, _
        WhereCondition:=Me.Filter
End Sub
于 2013-08-01T18:35:07.663 回答