Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

Print to PDF From Access

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Smith - 31 May 2004 15:21 GMT
How can we specifiy a printer in VBA code?..  The problem is that when I
print some report, I want them to print to PDF File instead of the Default
Printer

Thanks!

JS
Dirk Goldgar - 31 May 2004 17:09 GMT
> How can we specifiy a printer in VBA code?..  The problem is that
> when I print some report, I want them to print to PDF File instead of
> the Default Printer

That depends on what version of Access you have installed, and what PDF
"printer".  I'm using Access 2002, which has a Printer object and
Printers collection that can be used as shown in the code below.  (Note:
this code is expecting the find the CutePDF printer, but failing that
will attempt to print to any printer with "PDF" in its name.)

'----- start of code (watch out for line wraps) -----
Private Sub cmdPDF_Click()

   Dim prt As Printer
   Dim intPrt As Integer

   If IsNull(Me.txtFromDate) Then
       MsgBox "Please enter the From date first!"
       Me.txtFromDate.SetFocus
       Exit Sub
   End If

   With Application.Printers

      ' Look first for the CutePDF printer.
       For intPrt = 0 To (.Count - 1)
           If .Item(intPrt).DeviceName = "CutePDF Printer" Then
               Set prt = .Item(intPrt)
               Exit For
           End If
       Next intPrt

       ' Did we find the CutePDF printer?
       If prt Is Nothing Then
           ' No.  Search for any PDF printer.
           For intPrt = 0 To (.Count - 1)
               If InStr(.Item(intPrt).DeviceName, "PDF") > 0 Then
                   Set prt = .Item(intPrt)
                   Exit For
               End If
           Next intPrt
       End If

   End With

   ' Did we find a PDF printer?
   If prt Is Nothing Then
       MsgBox "Sorry, I can't find a PDF printer installed on your
system!", _
               vbExclamation, "No PDF Printer"
   Else
       Set Application.Printer = prt

       DoCmd.OpenReport conTimeSheetReport, acViewNormal

       Set Application.Printer = Nothing
       Set prt = Nothing

   End If

End Sub
'----- end of code -----

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Kris Bishop - 13 Apr 2005 21:09 GMT
This is a great piece of code.  What can we use in place of the printer
object for those of us who don't have 2002?  I'm operating off of Access
2000.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.