Rastro_Jetson
Registered User.
- Local time
- Today, 15:12
- Joined
- Mar 1, 2017
- Messages
- 12
Dear all, newbie to vba.
I've spend hours cobbling this together from various sites on line. I'll gladly take the chastisement if someone can correct my mistakes. :^)
Table with looped value is "tbl_Carrier_IDs". Looped field is "Carrier_ID". When I run the code I get a "Enter Parameter Value" [Carrier_ID], so I know that is wrong. If I enter valid values there, it runs the report (for all clients in one report) and then gives me the Run Time 2501 error, "OutpuTo action was cancelled".
Please let me know if you can see any glaring mistakes that would turn this boat anchor into a Concorde. Thanks in advance. :^))
*****
Public Sub ExportToPDF()
Const Folder = "C:\Users\Me\Desktop\Access Loop"
Const Domain = "tbl_Carrier_IDs"
Const LoopedField = "Carrier_ID"
Const ReportName = "rpt_Example"
Dim rs As DAO.Recordset
Dim LoopedFieldValue As String
Dim FileName As String
Dim FullPath As String
Dim strWhere As String
Set rs = CurrentDb.OpenRecordset(Domain)
Do While Not rs.EOF
LoopedFieldValue = rs.Fields(LoopedField)
FileName = LoopedFieldValue & ".PDF"
FullPath = Folder & FileName
strWhere = LoopedField & " = " & LoopedFieldValue
Debug.Print FullPath
Debug.Print strWhere
DoCmd.OpenReport ReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
DoCmd.Close acReport, rpt_Example
rs.MoveNext
Loop
End Sub
I've spend hours cobbling this together from various sites on line. I'll gladly take the chastisement if someone can correct my mistakes. :^)
Table with looped value is "tbl_Carrier_IDs". Looped field is "Carrier_ID". When I run the code I get a "Enter Parameter Value" [Carrier_ID], so I know that is wrong. If I enter valid values there, it runs the report (for all clients in one report) and then gives me the Run Time 2501 error, "OutpuTo action was cancelled".
Please let me know if you can see any glaring mistakes that would turn this boat anchor into a Concorde. Thanks in advance. :^))
*****
Public Sub ExportToPDF()
Const Folder = "C:\Users\Me\Desktop\Access Loop"
Const Domain = "tbl_Carrier_IDs"
Const LoopedField = "Carrier_ID"
Const ReportName = "rpt_Example"
Dim rs As DAO.Recordset
Dim LoopedFieldValue As String
Dim FileName As String
Dim FullPath As String
Dim strWhere As String
Set rs = CurrentDb.OpenRecordset(Domain)
Do While Not rs.EOF
LoopedFieldValue = rs.Fields(LoopedField)
FileName = LoopedFieldValue & ".PDF"
FullPath = Folder & FileName
strWhere = LoopedField & " = " & LoopedFieldValue
Debug.Print FullPath
Debug.Print strWhere
DoCmd.OpenReport ReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
DoCmd.Close acReport, rpt_Example
rs.MoveNext
Loop
End Sub