Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Kendrick, Idaho, USA
    Thanked 0 Times in 0 Posts

    Set report margins on open (2000)

    Because Access is prone to losing report page setups, I would like to manually set the page margins when the report is opened. Suggestions on how?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Set report margins on open (2000)

    Sorry for the delay in replying, your post somehow slipped through the mazes.

    Others will correct me if I'm wrong, but I think you'll have to open the report in design view to set the margins in code in Access 2000. So you would have to call code to do this from a form, for instance, before opening the report in preview mode.

    The following code should go into a standard module. The margins are expressed in twips; there are 20 twips in 1 point, or 1440 twips in 1 inch.

    Private Type str_PRTMIP
    strRGB As String * 28
    End Type

    Private Type type_PRTMIP
    xLeftMargin As Long
    yTopMargin As Long
    xRightMargin As Long
    yBottomMargin 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

    Public Sub SetMargins _
    (ByVal strName As String, _
    sngLeft As Single, sngTop As Single, _
    sngRight As Single, sngBottom As Single)

    Const OneInch = 1440
    Dim PrtMipString As str_PRTMIP
    Dim PM As type_PRTMIP
    Dim rpt As Report

    ' Open the report.
    DoCmd.OpenReport strName, acViewDesign
    Set rpt = Reports(strName)
    PrtMipString.strRGB = rpt.PrtMip
    LSet PM = PrtMipString

    ' Set margins.
    PM.xLeftMargin = sngLeft * OneInch
    PM.yTopMargin = sngTop * OneInch
    PM.xRightMargin = sngRight * OneInch
    PM.yBottomMargin = sngBottom * OneInch

    ' Update property.
    LSet PrtMipString = PM
    rpt.PrtMip = PrtMipString.strRGB

    DoCmd.Close acReport, strName, acSaveYes
    Set rpt = Nothing
    End Sub

    You can call this as follows:

    SetMargins "rptDemo", 2, 0.5, 1, 1.5
    DoCmd.OpenReport "rptDemo", acViewPreview

    <img src=/w3timages/blueline.gif width=33% height=2>

    Note: Access 2002 has a new Printer object that can be used to set the margins. It can be done in the On Open event of the report.

    Private Sub Report_Open(Cancel As Integer)
    Const OneInch = 1440
    With Me.Printer
    .LeftMargin = 2 * OneInch
    .TopMargin = 0.5 * OneInch
    .RightMargin = 1 * OneInch
    .BottomMargin = 1.5 * OneInch
    End With
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts