In ACCESS 2013, what is the best method for setting an application to print to "odd" printers that may have different names on different PC's

I have an application that needs to print ID Cards on a PVC card printer with all margins set at .01", Landscape, and a paper size of "CR-80".
I am constantly making minor changes to the FRONTEND file and sending it out to all the sites, and I have to remember to change the SPECIFIC PRINTER in the PAGE SETUP of each REPORT that prints an ID CARD.

Some sites have a FARGO DTC1250e, some have a MAGICARD(p), etc...  they are rarely named consistently even if they are the same model printer.

I use a table that holds various parameters for the application, and have set the exact printer name for each site's card printer.

The challenge is, that if ACCESS ever tries to print one of those reports, and for what ever reason it can't see the right printer, then it pops up the screen that says "THIS REPORT WAS ORIGINALLY FORMATTED FOR .....",
depending on what the user does at that point, things can go horribly wrong.  

Is it possible to set (in VBA) the papersize, margins, orientation each time a report prints.
Or is there another method that would be a better option.

Below is what I'm currently doing to grab the right printer.  It works ok, unless there was a hiccup and someone tried to print the same report to a different printer.  then it seems like the orientation/margin/etc... settings are lost.


'<<<<<<<Begin Print Routine.............
'Get the name of the desired printer, and the DEFAULT printer in case there's a problem
Dim stReportPrinter As String
Dim stPrinterDefault As String
stPrinterDefault = Application.Printer.DeviceName

'Set the printer to use for this report
stReportPrinter = Nz(DLookup("[FieldValue]", "tblParameters", "[FieldName] = 'PrinterPVC'"), stPrinterDefault)
Set Application.Printer = Application.Printers(stReportPrinter)

Dim stReport As String
stReport = "rptCashCardPVC_1Up"
DoCmd.OpenReport stReport, acViewNormal
Set Application.Printer = Nothing

'...........>>>>>>>>>>End Print Routine

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't see how your DLookup for stReportPrinter could provide the correct printer name since it will always return the same record whether someone has a Fargo printer or a MAGICARD printer.

Seems to me you need to loop through the installed printers and see if they match one in your table, then set the default printer to the one that matched.  The following code show you the list of installed printers.

        Dim prtLoop As Printer
        For Each prtLoop In Application.Printers
            Debug.Print prtLoop.DeviceName                    
        Next prtLoop

Open in new window

TechGuiseAuthor Commented:
I'm just using tblParameters to hold "setup" information, for things that are specific to a particular site. (see graphic)screenshot of tblParameters
TechGuiseAuthor Commented:
I guess my question title was not the correct choice of words.  I really need a way to set the printer name (to whatever is in tblParameters), then set the margins, orientation, paper size.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Okay, so the site in the image has a FARGO DTC1250e printer.  Where do you get the setup information for a site that has the MAGICARD printer?

Also, why do you set it to Specific Printer on the page setup of the report?  Why not use Default Printer since you are changing the application default printer anyway in your code?

TechGuiseAuthor Commented:
If I use the default printer, I can't guarantee what the margins, orientation, page size will be set to.

In an attempt to work around that, I can set the Page Size and Orientation in the printer under DEVICES and PRINTERS, but there is not setting for the margins.
TechGuiseAuthor Commented:
I just change the FIELDVALUE of item #30 for whatever the site has for an ID Card Printer (change it to the exact name of that specific printer on that machine)
That table is located in the BACKEND file, so I only have to input it once when I first load the app on that machine.
You can either have two reports, one made for each specific printer.
Or make use of the Printer Object options to set all the other parameters.  You are already using the Printer object to set your default printer.  Here's how you would set the other parameters:
Private Sub Report_Open(Cancel As Integer)
    With Me.Printer 
        .PaperSize = acPRPSLegal
        .Orientation = acPROPLandscape 
        .BottomMargin = 1 * 1440
        .TopMargin = 1 * 1440
        .LeftMargin = 0.5 * 1440
        .RightMargin = 0.5 * 1440
    End With

End Sub

Open in new window

To see what other options you can change, following this link and check out the Printer Members and Properties on the left hand side:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TechGuiseAuthor Commented:
Any idea how I would set the paper size to "CR-80"?

Assuming it might be using the "acPRPSUser", but that's just a guess.
Or is there a list somewhere as to what the sizes are of all the "acPRPxxx" choices?
If you follow the link on the left called Printer Members, then go down to the row for PaperSize and click on AcPrintPaperSize, you'll see the list,

TechGuiseAuthor Commented:
Thanks, this will get me further down the road.  
Would you know where I could get some examples of how to setup a User Defined size (acPRPSUser)
Sorry I've never tried using acPRPSUser.  I'm assuming if you set it to that, you would set the following (assuming 7.5" x 5" paper size):
DefaultSize = False
ItemSizeHeight = 7.5 * 1440
ItemSizeWidth =  5 * 1440

No guarantees though.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.