A
Antney
Hi,
I've listed several messages but I haven't found the right answer.
I'm trying to convert a report I have to a PDF. I want the code to label
each report respectively and place it in My Documents.
I've looked at Lebans code, which I am trying to use but to NO AVAIL! I've
copied over his dll's into the folder where my db is. I've copied over his
modules and classes into my db. I copied over his code, for the command
button. Everytime I hit the command button, my report starts to print from
the default printer. When I change the default to PDF, it brings up the
dialog box, which I don't want and then after the first report runs, I get an
error saying that the title is incorrect. What I am trying to do is print all
of my schools (110), label them respectively and place them all in a folder
of my choosing. I want to only click the print button once. I've copied over
my code. This is the only code I have for the print button and again, I have
Leban's modules and classes in my db along with the dll's in the folder.
If anyone could help, without referring me back to Leban's website, It would
be much appreciated.
Thanks!!!
Here's my code:
Option Compare Database
Option Explicit
' The function call is:
Public Function ConvertReportToPDF( _
Optional strReport As String = "", _
Optional SnapshotName As String = "", _
Optional strDocName As String = "", _
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = True, _
Optional CompressionLevel As Long = 150, _
Optional PasswordOpen As String = "", _
Optional PasswordOwner As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional PDFNoFontEmbedding As Long = 0, _
Optional PDFUnicodeFlags As Long = 0 _
) As Boolean
End Function
Private Sub cmdReportToPDF_Click()
On Error GoTo Err_cmdPrintReports_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReport As String
Dim strDocName As String
Dim blRet As Boolean
Set db = CurrentDb()
Set rs = db.OpenRecordset("qrySchools", dbOpenSnapshot)
strReport = "rptStudentDataSheet_0708"
With rs
Do Until (.EOF Or .BOF) = True
DoCmd.OpenReport strReport, acViewNormal, , "School = " &
rs("School")
Reports(strReport).Visible = False
strDocName = "C:\Documents and Settings\anthony.johnson\My
Documents\Anthony\ " & !SiteName & ".pdf"
blRet = ConvertReportToPDF(strReport, , strDocName, False,
False)
DoCmd.Close acReport, strReport
rs.MoveNext
Loop
End With
Exit_cmdPrintReports_Click:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
Err_cmdPrintReports_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Test subroutine..."
Resume Exit_cmdPrintReports_Click
End Sub
I've listed several messages but I haven't found the right answer.
I'm trying to convert a report I have to a PDF. I want the code to label
each report respectively and place it in My Documents.
I've looked at Lebans code, which I am trying to use but to NO AVAIL! I've
copied over his dll's into the folder where my db is. I've copied over his
modules and classes into my db. I copied over his code, for the command
button. Everytime I hit the command button, my report starts to print from
the default printer. When I change the default to PDF, it brings up the
dialog box, which I don't want and then after the first report runs, I get an
error saying that the title is incorrect. What I am trying to do is print all
of my schools (110), label them respectively and place them all in a folder
of my choosing. I want to only click the print button once. I've copied over
my code. This is the only code I have for the print button and again, I have
Leban's modules and classes in my db along with the dll's in the folder.
If anyone could help, without referring me back to Leban's website, It would
be much appreciated.
Thanks!!!
Here's my code:
Option Compare Database
Option Explicit
' The function call is:
Public Function ConvertReportToPDF( _
Optional strReport As String = "", _
Optional SnapshotName As String = "", _
Optional strDocName As String = "", _
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = True, _
Optional CompressionLevel As Long = 150, _
Optional PasswordOpen As String = "", _
Optional PasswordOwner As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional PDFNoFontEmbedding As Long = 0, _
Optional PDFUnicodeFlags As Long = 0 _
) As Boolean
End Function
Private Sub cmdReportToPDF_Click()
On Error GoTo Err_cmdPrintReports_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strReport As String
Dim strDocName As String
Dim blRet As Boolean
Set db = CurrentDb()
Set rs = db.OpenRecordset("qrySchools", dbOpenSnapshot)
strReport = "rptStudentDataSheet_0708"
With rs
Do Until (.EOF Or .BOF) = True
DoCmd.OpenReport strReport, acViewNormal, , "School = " &
rs("School")
Reports(strReport).Visible = False
strDocName = "C:\Documents and Settings\anthony.johnson\My
Documents\Anthony\ " & !SiteName & ".pdf"
blRet = ConvertReportToPDF(strReport, , strDocName, False,
False)
DoCmd.Close acReport, strReport
rs.MoveNext
Loop
End With
Exit_cmdPrintReports_Click:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
Err_cmdPrintReports_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Test subroutine..."
Resume Exit_cmdPrintReports_Click
End Sub