Solved Set printer options without opening report, is that possible in an .accde application (1 Viewer)

Avds

New member
Local time
Today, 22:54
Joined
Feb 14, 2022
Messages
6
my first post…..

The scenario:
- I have a print function that opens a report and opens it in a new window for print preview using acdialog (the customer specifically doesn't want the acViewPreview, , , acHidden as that opens it in the Access Window)
- based on the orientation (portrait or landscape) the duplex setting of the printer needs to be set correctly

The following works well BUT only in an .accdb and I want to lock the app for users into an .accde.
In the .accde the following error occurs: "the command you specified is not available in an .mde, .accde or .ade database" which must be because of the acViewDesign option. I don't know another way though to inquire the orientation of the report without opening it and I would not like to open it twice visibly for the user (once to get the orientation and secondly for the print preview in a separate window.
Any ideas how I can achieve this?

Function PrintDoc(DocName As String)

On Error GoTo Err_PrintDoc
DoCmd.OpenReport DocName, acViewDesign, , , acHidden
If Reports(DocName).Printer.Orientation = acPRORLandscape Then
Reports(DocName).Printer.Duplex = acPRDPVertical
Else
Reports(DocName).Printer.Duplex = acPRDPHorizontal
End If
DoCmd.Close acReport, DocName, acSaveYes
DoCmd.OpenReport DocName, acViewPreview, , , acDialog
Exit_PrintDoc:
Exit Function

Err_PrintDoc:
MsgBox Err.Description
Resume Exit_PrintDoc:

End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:54
Joined
Oct 29, 2018
Messages
21,455
Hi. Welcome to AWF!

Have you tried to see if opening the report using acHidden will work? Just a thought...
 

Avds

New member
Local time
Today, 22:54
Joined
Feb 14, 2022
Messages
6
Thanks! Yes I tried all the options but opening with acHidden and acPreview opens the report within the application window. The customer doesn’t want tabs and would like reports to open in a separate window so that they can look at the report preview and go into the application. That works perfectly with acDialog but then I lose control over the report and cannot set the duplex
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:54
Joined
Oct 29, 2018
Messages
21,455
Thanks! Yes I tried all the options but opening with acHidden and acPreview opens the report within the application window. The customer doesn’t want tabs and would like reports to open in a separate window so that they can look at the report preview and go into the application. That works perfectly with acDialog but then I lose control over the report and cannot set the duplex
Is your Document Window Type setting set to Overlapping Windows?
 

Avds

New member
Local time
Today, 22:54
Joined
Feb 14, 2022
Messages
6
No. it is set to tabbed but the customer doesn't want to see the tabs. I know but there are 15 users and they have had issues of switching between tabs and half entered data.

Having said that, I thought that I possible need to look outside of MS Access and have now resolved the issue with pdf. Instead of opening the report in acDialog, I now open it in pdf and they can now look at the report in a pdf viewer and continue work in Access. It also resolves the Duplex issue as the pdf reader takes care of it.

DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, stDownloadfolder & "\" & DocName & ".pdf", True
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:54
Joined
Feb 28, 2001
Messages
27,148
When you open Access, you implicitly see the printers defined for your copy of Windows on your desktop or laptop. From VBA, the properties of the default printer are available using Application.Printers, which is defined here:


The printers currently visible/available to Windows are in the collection of printers enumerated within Application.Printers, and one member of that collection is a Printer object. You can set the properties of the printer object, which allows you to see things listed in this link:


You can select which printer becomes your default with a simple VBA command:


Once you set those properties, any documents you print should use whatever properties you set and it should stay that way. HOWEVER, most printers these days are shared across a local network.

You can set your session's default printer properties, but you cannot programmatically set the PHYSICAL printer properties without network admin rights or going to the physical printer and accessing the console thereof. When you set printer properties for a report, what you REALLY do is attach a list of printer properties for each individual document. Since most folks will print on 8 1/2 x 11 plain paper, and since most offices load 8 1/2 x 11 plain paper to their shared printers, printing occurs automatically. However, if it happened that you set properties such as paper size or paper quality to something OTHER than what is currently set on the printer, you print job will hang in the print queue until someone loads the requested paper.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:54
Joined
Oct 29, 2018
Messages
21,455
Quick question. Did you also uncheck the box for Show Document Tabs?
 

Avds

New member
Local time
Today, 22:54
Joined
Feb 14, 2022
Messages
6
When you open Access, ……
Thanks for the extensive reply. Setting the properties was not the issue though, the command worked pretty well: Reports(DocName).Printer.Duplex = acPRDPHorizontal
 

Avds

New member
Local time
Today, 22:54
Joined
Feb 14, 2022
Messages
6
I have now resolved the issue with pdf. Instead of opening the report in acDialog, I now open it in pdf and they can now look at the report in a pdf viewer and continue work in Access. It also resolves the Duplex issue as the pdf reader takes care of it.

DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, stDownloadfolder & "\" & DocName & ".pdf", True
 

vhung

Member
Local time
Today, 05:54
Joined
Jul 8, 2020
Messages
235
I have now resolved the issue with pdf. Instead of opening the report in acDialog, I now open it in pdf and they can now look at the report in a pdf viewer and continue work in Access. It also resolves the Duplex issue as the pdf reader takes care of it.

DoCmd.OutputTo acOutputReport, DocName, acFormatPDF, stDownloadfolder & "\" & DocName & ".pdf", True
Good day...
Smart move, using PDF report is very necessary, specially for review of data and submission of reports on email.
 

Users who are viewing this thread

Top Bottom