【问题标题】:Vba in access. Filtering query访问中的 Vba。过滤查询
【发布时间】:2018-08-22 03:56:29
【问题描述】:

我在访问 vba 时遇到问题。我编写了一个代码来过滤表单并通过按钮生成报告。现在,当我运行查询时,如果我将报告放在与表单相同的页面上,它只会过滤并生成报告。有没有办法让我的报告单独创建?

Private Sub Search_Click()
    Dim strWhere As String
    Dim i As Variant
    Dim varItem As Variant
    Dim strDelim As String

    If Nz(Me.txtFullName, "") <> "" Then
        strWhere = strWhere & "FullName Like '*" & Replace(Me.txtFullName, "'", "''") & "*' AND "
    End If

    If Nz(Me.txtCivil, "") <> "" Then
        strWhere = strWhere & "CivilService_Status Like '*" & Replace(Me.txtCivil, "'", "''") & "*' AND "
    End If

    If Nz(Me.txtOffice, "") <> "" Then
        strWhere = strWhere & "Office_Title Like '*" & Replace(Me.txtOffice, "'", "''") & "*' AND "
    End If

    If Nz(Me.cboPosition, "") <> "" Then
        strWhere = strWhere & "[Full Time],[Part Time] = '" & Me.cboPosition.Value & "' AND "
    End If

    If Nz(Me.txtStartdate, "") <> "" Then
        strWhere = strWhere & "AgencyStart_Date Like '*" & Replace(Me.txtStartdate, "'", "''") & "*' AND "
    End If

    For Each i In Me.lstBureau.ItemsSelected 'listbox
        If Nz(Me.txtdivision, "") <> "" Then
            strWhere = strWhere & "Division Like '*" & Replace(Me.txtdivision, "'", "''") & "*' AND "
        End If
    Next i

    If strWhere <> "" Then
        strWhere = Left(strWhere, Len(strWhere) - 5)
        Report_Onboard_summary.Filter = strWhere
        Report_Onboard_summary.FilterOn = True
        'DoCmd.OpenReport "Onboard_summary", acViewReport, strWhere
    Else
        Report_Onboard_summary.Filter = ""
        Report_Onboard_summary.FilterOn = False
    End If
End Sub

任何帮助将不胜感激

【问题讨论】:

  • “与表单在同一页面上”是什么意思?

标签: vba ms-access


【解决方案1】:

我通常使用OpenReport 命令打开报告。

DoCmd.OpenReport "Report_Onboard_summary", acViewPreview, WhereCondition:=strWhere 

用于预览,或

DoCmd.OpenReport "Report_Onboard_summary", acViewNormal, WhereCondition:=strWhere 

用于立即打印。

这假定报表创建为单独存储在数据库中的Report 对象,而不是Form 对象。您说您将其存储在同一页面上,这使我相信您有一个子表单,而不是实际的Report

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-26
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
相关资源
最近更新 更多