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

access+training+london - printer change problems

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

access+training+london - Printer Change Problems

ResolvedVersion 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:

Random sampling

Data is th key to a good database, therefore checking is essential.

A good way of checking data is by random sampling. You can do this in a query, by typing the follow:
1) In the Field box create a RandonID field eg. Randon Id: Rnd(fieldname])

2) sort the field
3)Right click and chage the properties for To value to be the number of randon records you want to see.

4) Change the set to Show row for Randon ID to be False, add all the other fields you want to see and the run the query.

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.