循环和创建报告的不一致

时间:2016-06-01 19:19:49

标签: access-vba access

我有一个包含5个表,3个查询,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

1 个答案:

答案 0 :(得分:0)

您既可以打开报告进行预览,也可以输出为PDF。

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