Question choose printer to print your report

XXD

Registered User.
Local time
Yesterday, 23:20
Joined
Mar 11, 2008
Messages
68
Hi

How can I make so that when you press the print button a report shall be printed by a printer that i have wroten in the code?
to print a report i'm using this code

stDocName = "Report"
DoCmd.OpenReport stDocName, acNormal

but it prints out from the default printer. I don't want to change the default printer but just make so this button prints out a report form that printer.

thanks in advance
xxd
 
Not really what i need because i have two print buttons with different printers, and on that example it is not possible to print the same report on two different printers. Thanks for help though

xxd
 
Last edited:
This will bring up the print dialogue box

Hi There

Try this

Dim stDocName As String

DoCmd.RunCommand acCmdPrint
stDocName = "Your_Report_Name_Here"
DoCmd.OpenReport stDocName, acNormal

This will bring up the printer dialogue box where you can choose from a list of installed printers

Regards

Tony
 
Thanks, but is there a code that chooses a printer automaticlly?

xxd
 
Assign a printer to a specific report

Hi again

Yes there is, Try this:-

Public Function AssignReportPrinter(strDoc As String, strPrinterName As String) As Boolean
On Error GoTo Err_Handler
'Purpose: Set or remove a custom property for the report for a particular printer.
'Arguments: strDoc = name or report.
' strPrinterName = name of printer. Zero-length string to remove property.
'Return: True on success.
Dim db As DAO.Database
Dim doc As DAO.Document
Dim strMsg As String 'Error message.
Dim bReturn As Boolean

'Get a reference to the report document.
Set db = CurrentDb()
Set doc = db.Containers("Reports").Documents(strDoc)

If Len(strPrinterName) = 0 Then
'Remove the property (if it exists).
If HasProperty(doc, mstrcPropName) Then
doc.Properties.Delete mstrcPropName
End If
bReturn = True
Else
'Create or set the property.
If SetPropertyDAO(doc, mstrcPropName, dbText, strPrinterName, strMsg) Then
bReturn = True
Else
MsgBox strMsg, vbInformation, "Printer not set for report: " & strDoc
End If

I got this from Allen Brownes site

http://allenbrowne.com/AppPrintMgtCode.html#AssignReportPrinter

Regards

Tony
 

Users who are viewing this thread

Back
Top Bottom