Changing printer config in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Client has a macro to print a report. Is there a way to add some code to turn
off duplex printing? I'm not very fluent in VBA.

Thank you!
 
Thanks Tom.

I see in the 1st site there is a section dealing with duplex. It mentions a
Printer Property: Returns or sets an AcPrintDuplex constant indicating how
the specified printer handles the orientation of duplex (two-sided) printing.
An AcPrintDuplex constant can be one of the following:

acPRDPSimplex Single-sided printing with the current orientation setting.

Please help me understand how to put that into some code. I tried
Application.Printer.AcPrintDuplex = AcPRDPSimplex but get a compile error:
method or data member not found.

Please be patient with me - I am just not very knowledgable about VBA but
trying to learn more :)

Thank you!!!
 
Hi Mary,

I'm about as patient as they come, having taught at the Community College
level for three years! <smile>

I think you were very close, except that you need to use the property name,
which is Duplex. Try the following in the Immediate Window (open by pressing
the control key and G at the same time, ie. Ctrl G):

?Application.Printer.Duplex

You will likely get an integer returned, such as 1, 2 or 3. Now try setting
this property in the Immediate Window. For example, type:

Application.Printer.Duplex=acPRDPVertical or
Application.Printer.Duplex=acPRDPHorizontal

Then interrogate the current setting once more with:

?Application.Printer.Duplex


Did you download the sample database named "ODC_Acc10_Printers.exe", 351 KB?


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
So, after entering that information into the Immediate Window, what do I do
with the results?

I typed in ?application.Printer.Duplex pressed Enter and it returned a 1
Then on the next line in the Immediate window - I typed in
Application.Printer.Duplex=acPRDPSimplex
Pressed Enter and on the next line typed in ?Application.Printer.Duplex
which again gave me a 1.

Yes, I downloaded the database, but unfortunately it isn't helping much.

Thanks for your help and patience!!
 
Hi Mary,

The Immediate Window just provides a convenient method of running quick
tests, or printing stuff from a procedure using the Debug.Print statement. In
general, it is not intended to be used to make permanent changes.

The reason that you got a 1 the second time you issued the command:
?Application.Printer.Duplex

is that your initial setting was defaulted to acPRDPSimplex. So, when you
issued the command:

Application.Printer.Duplex=acPRDPSimplex

you were not changing anything. Thus the ?Application.Printer.Duplex
returned the same result. That's why I recommend trying it with the vertical
or horizontal constants.

I think one would just use the command within a procedure, such as the
following, however, I cannot properly test this because my printer does not
support duplex printing. Try something like this, for a command button named
"cmdPrint", after substituting a valid report name below:


Private Sub cmdPrint_Click()
On Error GoTo ProcError

Application.Printer.Duplex = acPRDPVertical

DoCmd.OpenReport "YourReportName"

ExitProc:
Exit Sub
ProcError:
Select Case Err.Number
Case 2501 'Report open cancelled
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in cmdPrint_Click event procedure ..."
End Select
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Tom,

Here is the code I'm trying:

Private Sub Print_Report_Click()
Application.Printer.Duplex = acPRDPSimplex
DoCmd.OpenReport "rptBookStatus"
DoCmd.PrintOut acPrintAll
End Sub

The report prints, but it is still double sided.
 
Tom,
The report is going to the default printer. Thanks for trying! If you think
of anything else to try, let me know!
 
Hi Mary,

I tried adding duplex capability to the sample that Microsoft provides as a
download. In the process, I discovered a bug in their code for populating the
list box with the reports in the database. The list box in frmPrinter
displays 13 available reports. However, I count 14 reports total. The missing
report is "Summary of Sales by Year".

Close the form. Try importing a report from another database. Reopen the
form. All appears well, as you can see the report that you just imported in
the list box. Close the form again. Do a compact and repair of the database.
Reopen frmPrinter. Oops, why isn't the newly imported report showing up? At
least *now* I can see the "Summary of Sales by Year" report! My simple fix
for this problem is to change the method that is used to populate the list
box. Set the Row Source Type to a Table/Query, and set the Row Source to the
following query:

SELECT msysobjects.Name AS Reports
FROM msysobjects
WHERE (((msysobjects.Type)=-32764))
ORDER BY msysobjects.Name;

Comment out (or remove) the line of code in Form_Open that clears the
listbox, ie.:

' Clear lstSelectReport and cboPrinter lists
' before loading the current lists of reports
' and printers.
With Me
!cboPrinter.RowSource = ""
' !lstSelectReport.RowSource = ""
End With

Finally, remove the code that the author used in Form_Open to populate the
list box:

' Loop through reports and add each to
' lstSelectReport list box. This loops through the
' AllReports collection in inverse order instead
' of using a For Each...Next statement so
' that reports are listed in alphabetical order.
Me!lstSelectReport.RowSourceType = "Value List"
intCount = CurrentProject.AllReports.Count - 1
Do While intCount > 0
Me!lstSelectReport.AddItem _
CurrentProject.AllReports(intCount).Name
intCount = intCount - 1
Loop


On the duplex issue, after *many* trips to a shared network printer at work
that includes duplex capability, I've generated a lot of paper for the
recycle bin. I've only been able to get a report to print on both sides of a
single sheet of paper about 5~10 percent of the time. The other 90~95 %, the
darn report just prints out single sided. I was using a report that included
two pages, so that I'd know for sure if it printed as intended. Pretty
frustrating, to say the least.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Back
Top