Solved

Report Printing

Posted on 2004-09-20
10
438 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now