?
Solved

Report Printing

Posted on 2004-09-20
10
Medium Priority
?
445 Views
Last Modified: 2008-02-01
I have a button on a form which should print a form.  But, I want to select my printer.  Using the wizard to create my button, it gives me VB code that prints the report using the default printer.

Please Help!
0
Comment
Question by:sbreen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 

Author Comment

by:sbreen
ID: 12105342
It should have read... I have a button on a form which should print a REPORT.
0
 
LVL 5

Expert Comment

by:broesi
ID: 12105367
Changing the code from

docmd.OpenReport "rptYourReportName"

to

docmd.OpenReport "rptYourReportName",acViewPreview

will open the report in print preview. There you can select the printer.

HTH,

broesi
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12105437
The code here will allow you to programmatically set a printer:

Option Compare Database   'Use database order for string comparisons
Option Explicit

' Code from:
' Microsoft Access 95 How-To
' (c) 1998 Ken Getz and Paul Litwin
' All rights reserved.

' You may only use this code as part of an application
' that requires its use. You must including this
' notice intact. You may not distribute the code
' as your own work, nor can you distribute the
' code on its own.

Function ahtGetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean

   ' Retrieve the default printer information. Though
   ' the function dutifully returns True if the
   ' values were available, and False otherwise, Windows
   ' really isn't happy without a default printer, and
   ' this situation rarely comes up.

   ' In:
   '     dr: a aht_tagDeviceRec structure to fill in
   ' Out:
   '     Return Value: True if info available, False otherwise.
   '     dr: filled in with default printer information,
   '        if it was available (check the function's return
   '        value).
   '
   ' Comments:
   '     Requires the ahtGetToken() function from basGetToken
   '     Requires the ahtGetINIString() function from basINIFile
   '     Requires type definitions from basPrintTypes
   
   Dim strBuffer As String

   strBuffer = ahtGetINIString("Windows", "Device")
   If Len(strBuffer) > 0 Then
      With dr
         .drDeviceName = ahtGetToken(strBuffer, ",", 1)
         .drDriverName = ahtGetToken(strBuffer, ",", 2)
         .drPort = ahtGetToken(strBuffer, ",", 3)
      End With
      ahtGetDefaultPrinter = True
   Else
      ahtGetDefaultPrinter = False
   End If
End Function

Function ahtSetDefaultPrinter(dr As aht_tagDeviceRec) As Boolean

   ' Set the default printer device in Win.INI

   ' In:
   '     dr: a aht_tagDeviceRec structure to use as
   '        the source of information.
   ' Out:
   '     Return Value: True if set correctly, False otherwise.
   '     If successful, writes a string in the form:
   '        device=HP LaserJet 4,HPPCL5E,LPT1:
   '     to your Win.INI file.
   '
   ' Comments:
   '     Requires the aht_apiWriteProfileString() declaration from basINIFile
   '     Requires type definitions from basPrintTypes

   Dim strBuffer As String

   ' Build up the appropriate string.
   strBuffer = dr.drDeviceName & ","
   strBuffer = strBuffer & dr.drDriverName & ","
   strBuffer = strBuffer & dr.drPort

   ' Now write that string out to WIN.INI.
   ahtSetDefaultPrinter = (aht_apiWriteProfileString("Windows", _
    "Device", strBuffer) <> 0)
End Function
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12105471
Sorry - you'll need the complete code, available here:
http://www.mvps.org/access/reports/rpt0009.htm

(on the link that says download the code DefaultPrt.zip)
0
 
LVL 1

Expert Comment

by:sonsofperez
ID: 12105521
Another option is that you can go to page setup in the report and tell it to print with a specific printer rather then the default printer.  However, this will only work if you always want the report to go to the same printer.  If you actually need to choose the printer each time then try shanes code.  
0
 

Author Comment

by:sbreen
ID: 12105615
I want a dialog box to appear that allows me to choose which printer that I want.  I do not want to "set" my default printer as something else, and then print using the default printer to acheive the result of printing the report.  (The 2 solutions given would work, but are work-arounds)

A bit more:  I actually have two buttons on my form.  The first one prints using the default printer.  (Works Great!) The second is the problem.  It should  give me a dialog box when pressed and ask me which printer I want to use. The reason I am doing this is because I want to create a PDF file from the report, and to do so, I need to select the PDF printer.  (If there is a better way to create the PDF that I am unaware of, please do share. :-)

Thanks -
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 1000 total points
ID: 12105666
You could use the command:

DoCmd.RunCommand acCmdPrint

However, you might be better off using the printer code to change to the Acrobat printer, print the report and then change it back.
0
 
LVL 1

Expert Comment

by:sonsofperez
ID: 12105672
Why not just open the report in acViewPreview and then chose the print option?  You will have one minor extra step, but nothing that is very time consuming.

If you chose to change the default printer in code then all you have to do is change it back to your original default printer before closing the code.  I do this with some of my reports and it works fine.
0
 

Author Comment

by:sbreen
ID: 12105684
Thanks for your help everyone!
0
 

Author Comment

by:sbreen
ID: 12105740
If this DB is to be used on multiple machines, and those machines don't have adobe, then it could be a problem.  Because of that, I will use the DoCmd.RunCommand acCmdPrint


It is good to know the other option as well.  Again Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question