By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,435 Members | 1,967 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Printer and Printing Tips

ADezii
Expert 5K+
P: 8,627
Recently, there seems to be several questions specifically related to Printers and changing Printing characteristics for Forms and Reports. For this reason alone, I decided to dedicate this week's Tip to these Topics. The Tip will actually consist of several Tips which I feel are very useful for all Users, from Newbies to Experts. In order to utilize the code contained within these Tips, you must have Access 2002 or later.
  1. How can I generate a List of available Printers?
    Expand|Select|Wrap|Line Numbers
    1. 'Prints a list of available Printers and thier Ports
    2. 'to the Immediate Window
    3. Dim prn As Printer
    4.  
    5. For Each prn In Application.Printers
    6.   Debug.Print prn.DeviceName & " on " & prn.Port
    7. Next prn
  2. How can I find the characteristics of the current Window's Default Printer?
    Expand|Select|Wrap|Line Numbers
    1. 'Lists specific characteristics of the Current Printer
    2. With Application.Printer
    3.   Debug.Print "Current Printer   : " & .DeviceName
    4.   Debug.Print "Device Driver Name: " & .DriverName
    5.   Debug.Print "Port Assignment   : " & .Port
    6. End With
  3. How do I fill a Combo Box with a list of Installed Printers?
    Expand|Select|Wrap|Line Numbers
    1. 'Fills a Combo Box with a list of Installed Printers
    2. Dim prn As Printer, cbo As ComboBox
    3. Dim strText As String
    4.  
    5. Set cbo = Me![cboPrinters]
    6.  
    7. 'Clear the control's list.
    8. cbo.RowSource = vbNullString
    9. cbo.RowSourceType = "Value List"
    10.  
    11. 'Set up three columns
    12. cbo.ColumnCount = 3
    13. cbo.ColumnWidths = "3in;1in;1in"
    14. cbo.Width = 5 * 1440    '5 inches (measured in Twips)
    15.  
    16.  
    17. 'Bind to the DeviceName column (1)
    18. cbo.BoundColumn = 1
    19.  
    20. For Each prn In Application.Printers
    21.   strText = prn.DeviceName & ";" & prn.DriverName & _
    22.             ";" & prn.Port
    23.   cbo.AddItem strText
    24. Next prn
  4. How do I change the Default Printer?
    Expand|Select|Wrap|Line Numbers
    1. 'Changes the Default Printer, then resets it to the original Printer.
    2. 'This will only work if the report is set up to Print to the Default
    3. 'Printer
    4.  
    5. Set Application.Printer = Application.Printers("Acrobat PDFWriter")
    6.   DoCmd.OpenReport "<Your Report Name>", acViewNormal, , , acWindowNormal
    7.  
    8. 'Reset the Default Printer back to the way it was
    9. Set Application.Printer = Nothing
  5. How do I print a Report to a specific device?
    Expand|Select|Wrap|Line Numbers
    1. 'The following code will Print rptInvoices to the Acrobat PFDWriter Printer
    2. Dim rpt As Report
    3.  
    4. DoCmd.OpenReport "rptInvoices", View:=acViewPreview, WindowMode:=acHidden
    5.  
    6. Set rpt = Reports("rptInvoices")
    7. Set rpt.Printer = Application.Printers("Acrobat PFDWriter")
    8.  
    9. DoCmd.OpenReport "rptInvoices"
    10. DoCmd.Close acReport, "rptInvoices"
  6. How can I modify Printer characteristics for a Form or Report?
    Expand|Select|Wrap|Line Numbers
    1. 'Open rptInvoices in Design view, change 3 of its Properties
    2. 'Print the report, and then close the report.
    3.  
    4. Const conReport As String = "rptInvoices"
    5.  
    6. DoCmd.OpenReport conReport, View:=acViewPreview, WindowMode:=acHidden
    7.  
    8. 'Force the printer to look to the upper bin for paper, print on
    9. 'Monarch-size envelopes, and Print two copies, set orientation to
    10. 'Landscape
    11. With Reports(conReport).Printer
    12.   .PaperBin = acPRBNUpper
    13.   .PaperSize = acPRPSEnvMonarch
    14.   .Copies = 2
    15.   .Orientation = acPRORLandscape
    16.   .Duplex = acPRDPVertical
    17.   .PrintQuality = acPRPQMedium
    18. End With
    19.  
    20. 'Now print the report.
    21. DoCmd.OpenReport conReport
    22. DoCmd.Close acReport, conReport
  7. How do I change the Layout characteristics for a Form or Report?
    Expand|Select|Wrap|Line Numbers
    1. Const conReport As String = "rptInvoices"
    2. Const conTwipsPerInch As Long = 1440
    3.  
    4. DoCmd.OpenReport conReport, View:=acViewPreview, WindowMode:=acHidden
    5.  
    6. 'Modify layout information. set up margins, columns, and
    7. 'print only data.
    8. With Reports(conReport).Printer
    9.   .LeftMargin = 0.5 * conTwipsPerInch
    10.   .RightMargin = 0.5 * conTwipsPerInch
    11.   .TopMargin = 1 * conTwipsPerInch
    12.   .BottomMargin = 1 * conTwipsPerInch
    13.   .ItemsAcross = 2
    14.   .ItemLayout = acPRHorizontalColumnLayout
    15.   .DefaultSize = False
    16.   .ItemSizeWidth = 3 * conTwipsPerInch
    17.   .ColumnSpacing = 0.1 * conTwipsPerInch
    18.   .DataOnly = True
    19. End With
    20.  
    21. DoCmd.OpenReport conReport
    22. DoCmd.Close acReport, conReport
Nov 19 '07 #1
Share this Article
Share on Google+
4 Comments


P: 5
I'm Immaculata
Thanks for what you just wrote, i got some help from here. But i'm currently working on a program for a school. My problem is tabularizing the results of my recordsets. i.e. I created a recordset, it got the data from the database and i want to print the output in a tabular form. Please how do i do this?
Jan 15 '08 #2

ADezii
Expert 5K+
P: 8,627
I'm Immaculata
Thanks for what you just wrote, i got some help from here. But i'm currently working on a program for a school. My problem is tabularizing the results of my recordsets. i.e. I created a recordset, it got the data from the database and i want to print the output in a tabular form. Please how do i do this?
I'm not exactly sure of what you are looking for, but this code will write the First Name, Last Name, and Address Fields of an Employees Table to a Text File (Recordset.txt) in the C:\Test\ Directory. The data will be Tabular and neatly formatted.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  2.  
  3. Set MyDB = CurrentDb()
  4. Set MyRS = MyDB.OpenRecordset("Select * From Employees", dbOpenSnapshot)
  5.  
  6. Open "C:\Test\Recordset.txt" For Output As #1
  7.  
  8. Do While Not MyRS.EOF
  9.   Print #1, MyRS![FirstName]; Tab(20); MyRS![LastName]; Tab(40); MyRS![Address]
  10.   MyRS.MoveNext
  11. Loop
  12.  
  13. Close #1
  14.  
  15. MyRS.Close
  16. Set MyRS = Nothing
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Nancy              Albericih           507 - 20th Ave. E. Moyamensing Avenue
  2. Andrew             Fuller              908 W. Capital Waykk
  3. Janet              Leverling           722 Moss Bay Blvd.
  4. Margaret           Peacock             4110 Old Redmond Rd.
  5. Steven             Buchanan            14 Garrett Hill
  6. Michael            Suyama              Coventry House and Miner Rd.
  7. Laura              Callahan            4726 - 11th Ave. N.E.
  8. Anne               Dodsworth           7 Houndstooth Rd.
  9. Robert             King                Edgeham Hollow Road
  10. Fred               Buchanan            14 Garrett Hill
Jan 17 '08 #3

P: 2
hi

i have a problem when i want to print the following message comes up: can't print or preview the page because the page size you selected is larger than 22.75 inches - any one can help me please
Jan 23 '08 #4

ADezii
Expert 5K+
P: 8,627
hi

i have a problem when i want to print the following message comes up: can't print or preview the page because the page size you selected is larger than 22.75 inches - any one can help me please
What exactly are you trying to Print?
Jan 23 '08 #5