button to print to Acrobat Distiller

G

Guest

I would like to create a button to print to my Acrobat Distiller. I know this
can be done through the Report's Page Setup however I don't always want the
report to print to the Acrobat Distiller. I figure the easiest solution is to
have a "Print" button that sends reports to the default printer and a "Print
to .pdf"
that sends reports to the Acrobat Distiller.

I currently use this Print button:
Private Sub Print_Click()
On Error GoTo Err_Print_Click

Dim stDocName As String
Dim strWhere As String
strWhere = "[txtProfileID] = """ & _
Forms![frmFinishedGoods].Form![txtProfileID] & """"
DoCmd.OpenReport Me!cbSelectReport, acNormal _
, , strWhere

Exit_Print_Click:
Exit Sub

Err_Print_Click:
MsgBox Err.Description
Resume Exit_Print_Click

End Sub

How can I modify this in order to create the "Print to .pdf" button?

As always, your help is greatly appreciated!
 
G

Guest

John,

I have the following procedure to print to distiller:

private sub printToDistiller(byval reportName as string, byval fileName as
string, rowFilter as string)
const extPDF as string = "pdf"
dim errNumber as long
dim errSource as string
dim orient as long
dim portName as string
dim newFileName as string
docmd.openReport reportName, acViewPreview, , rowFilter
if StrComp(Right(fileName, 4), extPDF, vbTextCompare) = 0 Then
fileName = Left(fileName, Len(fileName) - 4)
end If
' set the report caption
Reports(reportName).Caption = fileName

On Error Resume Next
With Reports(reportName)
orient = .Printer.Orientation
Set .Printer = Printers("Reports Distiller") ' the printer I created
specifically to print reports
portName = .Printer.Port
If .Printer.Orientation <> orient Then
.Printer.Orientation = orient
End If
End With

With Err
errNumber = .Number
errSource = .Source
End With
On Error GoTo 0

If errNumber <> 0 Then
DoCmd.Close acReport, reportName, acSaveNo
Err.Raise errNumber, errSource, "'Reports Distiller' printer is not
installed!"
End If

DoCmd.PrintOut
DoCmd.Close acReport, reportName, acSaveNo
' now copy the file to the correct location
newFileName = MyDestinationFolder & "\" & fileName & extPDF ' You will
need to put your destination folder path
fileName = Left(portName, Len(portName) - 5) & fileName & extPDF
On Error Resume Next
Kill newFileName
Do
If Len(dir(fileName)) Then Exit Do
Sleep 250 ' distiller may take some time to print the report
Loop
FileCopy fileName, newFileName
Kill fileName
end sub

And you will need to define the Sleep function:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Hope this helps
 
G

Guest

Hi, Sergey.

WOW! That's way over my head. How can I plug that into my existing code if
at all? Also, I'm not at all sure what you mean by "define Sleep function".

I'm LOST!

Sergey Poberezovskiy said:
John,

I have the following procedure to print to distiller:

private sub printToDistiller(byval reportName as string, byval fileName as
string, rowFilter as string)
const extPDF as string = "pdf"
dim errNumber as long
dim errSource as string
dim orient as long
dim portName as string
dim newFileName as string
docmd.openReport reportName, acViewPreview, , rowFilter
if StrComp(Right(fileName, 4), extPDF, vbTextCompare) = 0 Then
fileName = Left(fileName, Len(fileName) - 4)
end If
' set the report caption
Reports(reportName).Caption = fileName

On Error Resume Next
With Reports(reportName)
orient = .Printer.Orientation
Set .Printer = Printers("Reports Distiller") ' the printer I created
specifically to print reports
portName = .Printer.Port
If .Printer.Orientation <> orient Then
.Printer.Orientation = orient
End If
End With

With Err
errNumber = .Number
errSource = .Source
End With
On Error GoTo 0

If errNumber <> 0 Then
DoCmd.Close acReport, reportName, acSaveNo
Err.Raise errNumber, errSource, "'Reports Distiller' printer is not
installed!"
End If

DoCmd.PrintOut
DoCmd.Close acReport, reportName, acSaveNo
' now copy the file to the correct location
newFileName = MyDestinationFolder & "\" & fileName & extPDF ' You will
need to put your destination folder path
fileName = Left(portName, Len(portName) - 5) & fileName & extPDF
On Error Resume Next
Kill newFileName
Do
If Len(dir(fileName)) Then Exit Do
Sleep 250 ' distiller may take some time to print the report
Loop
FileCopy fileName, newFileName
Kill fileName
end sub

And you will need to define the Sleep function:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Hope this helps
JohnLute said:
I would like to create a button to print to my Acrobat Distiller. I know this
can be done through the Report's Page Setup however I don't always want the
report to print to the Acrobat Distiller. I figure the easiest solution is to
have a "Print" button that sends reports to the default printer and a "Print
to .pdf"
that sends reports to the Acrobat Distiller.

I currently use this Print button:
Private Sub Print_Click()
On Error GoTo Err_Print_Click

Dim stDocName As String
Dim strWhere As String
strWhere = "[txtProfileID] = """ & _
Forms![frmFinishedGoods].Form![txtProfileID] & """"
DoCmd.OpenReport Me!cbSelectReport, acNormal _
, , strWhere

Exit_Print_Click:
Exit Sub

Err_Print_Click:
MsgBox Err.Description
Resume Exit_Print_Click

End Sub

How can I modify this in order to create the "Print to .pdf" button?

As always, your help is greatly appreciated!
 
G

Guest

John,

Easy: you just put the sub into the same modue (or code behind) as your
current button click, and call it from within your click event passing the
report name, the output file name and optiional filter (strWhere in your
case) to it.

Defining Sleep means that the line must be in the same scope as the
printToDistiller sub - just put it at the top of the module.

I wish there was an easier way to print to distiller - after spending quite
a few hours (if not days) a couple of years ago I could not find anything
simpler than that :-(

HTH

JohnLute said:
Hi, Sergey.

WOW! That's way over my head. How can I plug that into my existing code if
at all? Also, I'm not at all sure what you mean by "define Sleep function".

I'm LOST!

Sergey Poberezovskiy said:
John,

I have the following procedure to print to distiller:

private sub printToDistiller(byval reportName as string, byval fileName as
string, rowFilter as string)
const extPDF as string = "pdf"
dim errNumber as long
dim errSource as string
dim orient as long
dim portName as string
dim newFileName as string
docmd.openReport reportName, acViewPreview, , rowFilter
if StrComp(Right(fileName, 4), extPDF, vbTextCompare) = 0 Then
fileName = Left(fileName, Len(fileName) - 4)
end If
' set the report caption
Reports(reportName).Caption = fileName

On Error Resume Next
With Reports(reportName)
orient = .Printer.Orientation
Set .Printer = Printers("Reports Distiller") ' the printer I created
specifically to print reports
portName = .Printer.Port
If .Printer.Orientation <> orient Then
.Printer.Orientation = orient
End If
End With

With Err
errNumber = .Number
errSource = .Source
End With
On Error GoTo 0

If errNumber <> 0 Then
DoCmd.Close acReport, reportName, acSaveNo
Err.Raise errNumber, errSource, "'Reports Distiller' printer is not
installed!"
End If

DoCmd.PrintOut
DoCmd.Close acReport, reportName, acSaveNo
' now copy the file to the correct location
newFileName = MyDestinationFolder & "\" & fileName & extPDF ' You will
need to put your destination folder path
fileName = Left(portName, Len(portName) - 5) & fileName & extPDF
On Error Resume Next
Kill newFileName
Do
If Len(dir(fileName)) Then Exit Do
Sleep 250 ' distiller may take some time to print the report
Loop
FileCopy fileName, newFileName
Kill fileName
end sub

And you will need to define the Sleep function:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Hope this helps
JohnLute said:
I would like to create a button to print to my Acrobat Distiller. I know this
can be done through the Report's Page Setup however I don't always want the
report to print to the Acrobat Distiller. I figure the easiest solution is to
have a "Print" button that sends reports to the default printer and a "Print
to .pdf"
that sends reports to the Acrobat Distiller.

I currently use this Print button:
Private Sub Print_Click()
On Error GoTo Err_Print_Click

Dim stDocName As String
Dim strWhere As String
strWhere = "[txtProfileID] = """ & _
Forms![frmFinishedGoods].Form![txtProfileID] & """"
DoCmd.OpenReport Me!cbSelectReport, acNormal _
, , strWhere

Exit_Print_Click:
Exit Sub

Err_Print_Click:
MsgBox Err.Description
Resume Exit_Print_Click

End Sub

How can I modify this in order to create the "Print to .pdf" button?

As always, your help is greatly appreciated!
 
G

Guest

Thanks, Sergey. Looks like I have my work cut out for me, too!
--
www.Marzetti.com


Sergey Poberezovskiy said:
John,

Easy: you just put the sub into the same modue (or code behind) as your
current button click, and call it from within your click event passing the
report name, the output file name and optiional filter (strWhere in your
case) to it.

Defining Sleep means that the line must be in the same scope as the
printToDistiller sub - just put it at the top of the module.

I wish there was an easier way to print to distiller - after spending quite
a few hours (if not days) a couple of years ago I could not find anything
simpler than that :-(

HTH

JohnLute said:
Hi, Sergey.

WOW! That's way over my head. How can I plug that into my existing code if
at all? Also, I'm not at all sure what you mean by "define Sleep function".

I'm LOST!

Sergey Poberezovskiy said:
John,

I have the following procedure to print to distiller:

private sub printToDistiller(byval reportName as string, byval fileName as
string, rowFilter as string)
const extPDF as string = "pdf"
dim errNumber as long
dim errSource as string
dim orient as long
dim portName as string
dim newFileName as string
docmd.openReport reportName, acViewPreview, , rowFilter
if StrComp(Right(fileName, 4), extPDF, vbTextCompare) = 0 Then
fileName = Left(fileName, Len(fileName) - 4)
end If
' set the report caption
Reports(reportName).Caption = fileName

On Error Resume Next
With Reports(reportName)
orient = .Printer.Orientation
Set .Printer = Printers("Reports Distiller") ' the printer I created
specifically to print reports
portName = .Printer.Port
If .Printer.Orientation <> orient Then
.Printer.Orientation = orient
End If
End With

With Err
errNumber = .Number
errSource = .Source
End With
On Error GoTo 0

If errNumber <> 0 Then
DoCmd.Close acReport, reportName, acSaveNo
Err.Raise errNumber, errSource, "'Reports Distiller' printer is not
installed!"
End If

DoCmd.PrintOut
DoCmd.Close acReport, reportName, acSaveNo
' now copy the file to the correct location
newFileName = MyDestinationFolder & "\" & fileName & extPDF ' You will
need to put your destination folder path
fileName = Left(portName, Len(portName) - 5) & fileName & extPDF
On Error Resume Next
Kill newFileName
Do
If Len(dir(fileName)) Then Exit Do
Sleep 250 ' distiller may take some time to print the report
Loop
FileCopy fileName, newFileName
Kill fileName
end sub

And you will need to define the Sleep function:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Hope this helps
:

I would like to create a button to print to my Acrobat Distiller. I know this
can be done through the Report's Page Setup however I don't always want the
report to print to the Acrobat Distiller. I figure the easiest solution is to
have a "Print" button that sends reports to the default printer and a "Print
to .pdf"
that sends reports to the Acrobat Distiller.

I currently use this Print button:
Private Sub Print_Click()
On Error GoTo Err_Print_Click

Dim stDocName As String
Dim strWhere As String
strWhere = "[txtProfileID] = """ & _
Forms![frmFinishedGoods].Form![txtProfileID] & """"
DoCmd.OpenReport Me!cbSelectReport, acNormal _
, , strWhere

Exit_Print_Click:
Exit Sub

Err_Print_Click:
MsgBox Err.Description
Resume Exit_Print_Click

End Sub

How can I modify this in order to create the "Print to .pdf" button?

As always, your help is greatly appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top