【问题标题】:Inconsistencies in looping through and creating reports循环和创建报告的不一致
【发布时间】:2020-07-06 16:13:57
【问题描述】:

我有一个包含 5 个表、3 个查询、3 个报告(查询是记录集)和三个报告的数据库,每个报告显示记录集中的几个字段。问题是,即使它们具有相同的代码,其中一个子例程的结果也不一致。就像它在每个主管之间循环并创建一个报告然后再做一次,它陷入了一个循环,我看不出问题出在哪里。希望有人可以提供帮助。

Private Sub cmdFedInvest_Click()
Dim x           As String
Dim y           As String
Dim StrSQL      As String
Dim stWhereStr  As String 'Where Condition'
Dim stSection   As String 'Selection from drop down list
Dim stfile      As String
Dim stDocName   As String
Dim StrEmail    As String

StrSQL = "SELECT DISTINCTROW [qryActT8_Sup].[Sup], [qryActT8_Sup].Sup_email " & _
"FROM [qryActT8_Sup];"
    y = Year(Date)

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Dim qdTemp As DAO.QueryDef
Set qdTemp = db.CreateQueryDef("", StrSQL)
Set rst = qdTemp.OpenRecordset()

If rst.EOF And rst.BOF Then
    MsgBox "No data available for the Ledger Process routine."
Else
    Debug.Print rst.Fields.Count
    rst.MoveFirst
    Do While Not rst.EOF
        x = rst![Sup]
        StrEmail = rst![Sup_email]
        stDocName = "FedInvest - ISSR - T8 Recertification Report"
        stWhereStr = "[qryActT8_Sup].[SUP]= '" & x & "'"
        stfile = Me.txtLocationSaveFI & "\" & x & " - " & y & " FedInvest Recertification.pdf"
        DoCmd.OpenReport stDocName, acPreview, , stWhereStr
        'DoCmd.SendObject acSendReport, stDocName, acFormatPDF, StrEmail, , , "2016 FedInvest Recertification", ""
        DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, stfile
        DoCmd.Close acReport, stDocName
        rst.MoveNext
   Loop
End If
rst.Close
Set rst = Nothing
End Sub

【问题讨论】:

    标签: vba ms-access


    【解决方案1】:

    您打开报告进行预览和输出到 PDF。

    如果只需要 PDF,请跳过预览。

    【讨论】:

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