Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Report Printing

Posted on 2004-09-20
10
Medium Priority
?
447 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

886 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