austenr
08-12-2015, 08:00 AM
Usually dont cross post but under the gun. This is crossposted here ; http://www.utteraccess.com/forum/index.php?showtopic=2030852&st=0&gopid=2553323&#entry2553323
What I need to do is DoCmd.OutputTo a PDF File instead of printing the report as it is set up now. Here is the code:
Public Function RunRpt()
' Turn off warnings
DoCmd.SetWarnings (WarningsOff)
' Define variables
Dim RptNm As String
RptNm = "Advanced Booking Report"
Dim SetMbr As String
' Database
' --------------------
' Define variables
' Open Database, Define Recordset
' Manually move to first record
Dim DB As Database, RS As Recordset
Dim RecordCount As Long
On Error GoTo ErrorHandler
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("tmp-Rptg-SET Members")
' Get number of records.
RS.MoveLast
RecordCount = RS.RecordCount
' Re-position to first row in RecordSet.
RS.MoveFirst
' Loop through the Rows in table, tmp-Rptg-SET-Members
For i = 0 To RecordCount - 1
' Set variable to build dynamic SQL WHERE clause using RS!SET Member
SetMbr = RS![SET Member]
SQLStr = "[SET Member] = " & "'" & SetMbr & "'"
' Prompt end user to save report using SET Member name
MsgBox "Save As " & SetMbr
' Open Report using dynamic SQL, output prompted
DoCmd.OpenReport RptNm, , , SQLStr, acHidden
'DoCmd.OutputTo acOutputReport, "RptNm", acFormatPDF, "SQLStr.pdf", True
RS.MoveNext
Next i
' Close Recordset, then Database
RS.Close
DB.Close
MsgBox "Report Run Completed: " & Now
' Turn on warnings
DoCmd.SetWarnings (WarningsOn)
Exit Function
ErrorHandler:
MsgBox Error
Exit Function
End Function
Please show me what the commented out DoCmd.OutputTo should look like. Thanks.
What I need to do is DoCmd.OutputTo a PDF File instead of printing the report as it is set up now. Here is the code:
Public Function RunRpt()
' Turn off warnings
DoCmd.SetWarnings (WarningsOff)
' Define variables
Dim RptNm As String
RptNm = "Advanced Booking Report"
Dim SetMbr As String
' Database
' --------------------
' Define variables
' Open Database, Define Recordset
' Manually move to first record
Dim DB As Database, RS As Recordset
Dim RecordCount As Long
On Error GoTo ErrorHandler
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("tmp-Rptg-SET Members")
' Get number of records.
RS.MoveLast
RecordCount = RS.RecordCount
' Re-position to first row in RecordSet.
RS.MoveFirst
' Loop through the Rows in table, tmp-Rptg-SET-Members
For i = 0 To RecordCount - 1
' Set variable to build dynamic SQL WHERE clause using RS!SET Member
SetMbr = RS![SET Member]
SQLStr = "[SET Member] = " & "'" & SetMbr & "'"
' Prompt end user to save report using SET Member name
MsgBox "Save As " & SetMbr
' Open Report using dynamic SQL, output prompted
DoCmd.OpenReport RptNm, , , SQLStr, acHidden
'DoCmd.OutputTo acOutputReport, "RptNm", acFormatPDF, "SQLStr.pdf", True
RS.MoveNext
Next i
' Close Recordset, then Database
RS.Close
DB.Close
MsgBox "Report Run Completed: " & Now
' Turn on warnings
DoCmd.SetWarnings (WarningsOn)
Exit Function
ErrorHandler:
MsgBox Error
Exit Function
End Function
Please show me what the commented out DoCmd.OutputTo should look like. Thanks.