Solved

Report Printing

Posted on 2004-09-20
10
444 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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 250 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

Industry Leaders: 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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

688 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