98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Access Training and help » access+training+london - Printer Change Problems
access+training+london - Printer Change Problems
Resolved · Low Priority · Version Standard
Martin has attended:
Access Advanced course
Access Intermediate course
Printer Change Problems
I change my default printer for the application in VBA but the margins do not carry over to the new printer.
I use the Application.Printer.TopMargin = objOldPrinter.TopMargin but the value returned is always 0.
Any Ideas.
Thanks
RE: Printer Change Problems
Hi Martin,
Sounds like objOldPrinter no longer exists? Make sure this is being assigned somewhere in your code. ie. print it out to the screen immediately after you set it. And then continue printing out the value further and further down your code until you get to the print command.
Also, couldn't you just set the margin in this line of code yourself? ie. if you know the margin was 2.6, couldn't you just have the code as:
Application.Printer.TopMargin = 2.6;
Let me know how you get on.
Regards, Rich
RE: Printer Change Problems
Thanks for the reply Rich. I dont think the old printer variable has gone out of scope. Here is the code I am using
Private Sub PrintReport(ByVal strPrinterName As String)
Dim objNewPrinter As Printer, objCurrPrinter As Printer, objP As Printer
For Each objP In Printers
If objP.DeviceName = strPrinterName Then
Set objNewPrinter = objP
Exit For
End If
Next
Set objCurrPrinter = Application.Printer
Application.Printer = objNewPrinter
With Application.Printer
.Orientation = objCurrPrinter.Orientation
.Duplex = acPRDPHorizontal
.LeftMargin = objCurrPrinter.LeftMargin
.RightMargin = objCurrPrinter.RightMargin
.TopMargin = objCurrPrinter.TopMargin
.BottomMargin = objCurrPrinter.BottomMargin
End With
DoCmd.OpenReport "rptRiskAssesment", acViewNormal
Application.Printer = objCurrPrinter
DoCmd.Close acForm, "frmPrintOptions"
End Sub
In a nutshell, it finds the printer based on the name passed to it and assigns it to a printer object. The actual application printer is stored in another printer object and replaced with the new printer. The margins, orientation and Duplex are passed to the new printer and the report is printed. Finally the old printer is replaced.
The orientation passes correctly but not the other settings. Does the printer carry margin settings or are these held in the report? One reason for the code to work like this is so that if he user selects the PDF printer option, the save as dialog pops up without them having to press to many buttons!
Many Thanks
RE: Printer Change Problems
Hi Martin,
I'll ask one of our VBA experts to have a look at this for you.
Regards, Rich
RE: Printer Change Problems
Martin
I have passed this on to my colleague Jacob for review.
Regards
Carlos
Training information:
See also:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Access tip:Switchboard StartupAn option when you open your Access database that contains all of you tables, forms and queries is only the switchboard is displayed. |