access+training+london - printer change problems

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access Training and help » access+training+london - Printer Change Problems

access+training+london - Printer Change Problems

resolvedResolved · 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


 

Access tip:

Switchboard Startup

An option when you open your Access database that contains all of you tables, forms and queries is only the switchboard is displayed.

To achieve this, select Tools click on Startup. On the right hand side of the Startup screen you are able to select which form you want to open when you open you Access Database. Once you have selected this, there is a check box just below that says "Display Database Window", you need to uncheck this option. Then click ok.

Then when you close you Access database and re open it, the database should open with just the switchboard being shown


View all Access hints and tips


Server loaded in 0.09 secs.