Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing printer properties

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I need to change the oritation/size of the paper for some printout. Is there a way to do this within the code so the user don't need to change the printer properties manually every now and then. Any help much appreciated.
 
Hi there,

If you're talking about one item that always needs to print in a way that's different everything else, try setting the page setup or print properties for that item. File -> Page Setup. You can specify a printer, margin size, landscape vs. portrait, etc that will always be applied to that item.

Hope this is what you were looking for,
Cj
 
Not shure what you want do you want to set marg/orint once and for all or du you want to be able to change this from time to time?
You should know that you will not be able to do anything to the report "on the fly" only before print (or after)
I have here a small function that calls the page setup without having to display the actual report:

Public Function PrintSetup(Rap As String)
On Error Resume Next

DoCmd.Echo False ', "Change setup for " & Rap
DoCmd.SelectObject acReport, Rap, True
DoCmd.RunCommand acCmdPageSetup
DoCmd.RunCommand acCmdWindowHide
DoCmd.Echo True
End Function
 
Sorry, I should have explained some more. Here is the exact situation :

I have a function the prints many reports / queries. Some of them need to be printed on Legal paper while others need be printed on Letter. Same thing for orientation : Some are landscape and other portrait. I want to set those properties in the function so the user won't have to set them between each Report/Query. Thanx
 
You can setup each report once and for all and save this setup, but somehow I do not think thats what you are looking for so try this:

VM=Left margen
HM=Right -
TM=Top -
BM=Bottom -

Public Sub ChPrtLayout(RapName As String)
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
Dim Marg, VM, HM, TM, BM

DoCmd.Echo False
Marg = 1440 / 25 '1 mm
VM = DLookup("VM", "WF_RapSize", "ReportName='" & RapName & "'")
HM = DLookup("HM", "WF_RapSize", "ReportName='" & RapName & "'")
TM = DLookup("TM", "WF_RapSize", "ReportName='" & RapName & "'")
BM = DLookup("BM", "WF_RapSize", "ReportName='" & RapName & "'")
DoCmd.OpenReport RapName, acDesign

Set rpt = Reports(RapName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.xLeftMargin = VM * Marg ' Set margins.
PM.yTopMargin = TM * Marg
PM.xRightMargin = HM * Marg
PM.yBotMargin = BM * Marg
LSet PrtMipString = PM ' Update property.
rpt.PrtMip = PrtMipString.strRGB

ExitHere:
On Error Resume Next
'Set pl = Nothing
Set rpt = Nothing
DoCmd.Close acReport, RapName, acSaveYes
DoCmd.Echo True
Exit Sub

HandleErrors:
' Rudimentary error handling...
MsgBox "Error: " & Err.Description & _
" (" & Err.Number & ")"
Resume ExitHere
End Sub

I have a table where I have the name for the user, the actual name of the report the 4 margens AND the 4 org margins if the user fumbles the setup he/she can get back to normal and the orientation land/port. (true/false)

Function SwitchOrient(RapName As String, Orint As Boolean)
On Error GoTo HandleErrors
Const DM_PORTRAIT = 1
Const DM_LANDSCAPE = 2
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report

DoCmd.Echo False
DoCmd.OpenReport RapName, acDesign
Set rpt = Reports(RapName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or _
DM.intOrientation ' Initialize fields.
'If DM.intOrientation = DM_PORTRAIT Then
If Orint Then
DM.intOrientation = DM_LANDSCAPE
Else
DM.intOrientation = DM_PORTRAIT
End If
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If

ExitHere:
On Error Resume Next
Set rpt = Nothing
DoCmd.Close acReport, RapName, acSaveYes
DoCmd.Echo True
Exit Function

HandleErrors:
' Rudimentary error handling...
MsgBox "Error: " & Err.Description & _
" (" & Err.Number & ")"
Resume ExitHere
End Function

And to make the whole thing work on the top of your module:
Option Compare Database
Option Explicit
Type str_PRTMIP
strRGB As String * 28
End Type
Type type_PRTMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
fDataOnly As Long
xWidth As Long
yHeight As Long
fDefaultSize As Long
cxColumns As Long
yColumnSpacing As Long
xRowSpacing As Long
rItemLayout As Long
fFastPrint As Long
fDatasheet As Long
End Type

Type str_DEVMODE
RGB As String * 94
End Type

Type type_DEVMODE
strDeviceName As String * 16
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 16
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Hope this does the trick for you - works here ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top