我正在尝试配置一个函数,该函数将根据用户输入他们想要的报告类型和他们想要保存的文件路径,为用户自动生成pdf文件夹。 一些说明:
错误2501 出现在2-76个循环重复之间,很少出现在同一个点上 两次。偶尔,整个事情都会运行,但我无法交出 偶尔运行的东西。 -
当前代码:
Sub RunThatReport(CReport As String, CPath As String)
'dimension variables
Dim dbs1 As Database, rst As Recordset
Dim Can8 As Double, vend As String
Dim Location As String, CFilePath As String
'create a filename
Select Case CReport
Case "rpt_Form-1"
Location = "_Form-1.pdf"
DoCmd.OutputTo acOutputReport, "rpt_all_lines", acFormatPDF, CPath & "\Lines Required.pdf", False
Case "rpt_Form-2"
Location = "_Form-2.pdf"
Case "rpt_Form-3"
Location = "_Form-3.pdf"
Case Else
Exit Sub
End Select
'Get the AN8 of all lines
Set dbs1 = CurrentDb
Set rst = dbs1.OpenRecordset("tbl_all_lines_to_run", dbOpenDynaset)
rst.MoveFirst
'loop through the lines
Do While Not rst.EOF
If Not IsNull(rst!AN8) Then
Can8 = rst!AN8 'I know this assignment is not actually necessary
vend = Replace(Replace(Replace(Trim(rst!Name), "/", "-"), "\", "-"), ".", "")
'CFilePath = CPath & "\" & vend & Location
CFilePath = CPath & "\" & Can8 & Location
Debug.Print vend & ": " & Can8 & " " & CFilePath 'This is my check to look at what was getting hung up
DoCmd.OpenReport CReport, acViewReport, , "ABAN8 =" & rst!AN8 'open report only for that line type
DoCmd.OutputTo acOutputReport, CReport, acFormatPDF, CFilePath, False
'DoCmd.Close acReport, CReport, acSaveNo
'waiting (2) 'This was my delay function
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
dbs1.Close
DoCmd.Close acReport, CReport, acSaveNo
End Sub