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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Margins for Report

Status
Not open for further replies.

sunnyjassal

Programmer
Feb 19, 2003
16
US
I found a piece of code online that one can set the paper size and the orientation of the report. the code is below.

But what I want to know is how can I set margins programtically just the way landscape or portrait orientation can be set.

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

Public Function SetOrientation(strName As String, orientation As Integer)
Dim rpt As Report
Dim strDevModeExtra As String
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE

DoCmd.OpenReport strName, acViewDesign 'Opens report in Design view.

Set rpt = Reports(strName)

If Not IsNull(rpt.PrtDevMode) Then

strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.lngFields = DM.lngFields Or DM.intOrientation 'Initialize fields.
DM.intOrientation = orientation 'Landscape

LSet DevString = DM 'Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
DoCmd.Save acReport, strName
DoCmd.Close acReport, strName
End If
DoCmd.OpenReport strName, acViewPreview
End Function


Any help will be appreciated.

Thanks,

Sunny Jassal
 
Sunny Jassal,

You didn't indicate which version of Access you are using, though I am not sure it matters.

A2K and earlier are limited to a PRTMIP property that allow programmatic settings of report margins. However this property is only available in design view. This will limit the property's availibility to MDB versions only. Perhaps someone can verify whether additional functionality has finally been exposed with the 2003 version.

The following thread should get you going: thread703-88957

Note that the report will need to be opened in design view, the related Prtmips code run and then the report can be returned to preview.

Cheers,
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top