开发者

An Access Problem:How to Set Access Report paper size A3 through VBA code

I want to set access report paper size to A3 permanently whenever user print it through VBA code . For that I have written this code which I have found over net

Option Compare Database

Type gtypStr_DEVMODE
    RGB As String * 94
End Type

Type gType_DEVMODE
    strDeviceName As String * 32
    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 * 32
    lngPad As Long
    lngBits As Long
    lngPW As Long
    lngPH As Long
    lngDFI As Long
    lngDFr As Long
End Type

Sub SetToA3(pReport As String)

    Dim LDevString As gtypStr_DEVMODE
    Dim LDM As g开发者_开发问答Type_DEVMODE
    Dim LDevModeExtra As String
    Dim LRpt As Report

    On Error GoTo Err_Execute

    'Open report in Design view
    DoCmd.OpenReport pReport, acDesign
    Set LRpt = Reports(pReport)

    'Change paper size to legal
    If Not IsNull(LRpt.PrtDevMode) Then

        LDevModeExtra = LRpt.PrtDevMode
        LDevString.RGB = LDevModeExtra
        LSet LDM = LDevString

        '5=legal, 1=standard
        LDM.intPaperSize = 256
        LSet LDevString = LDM
        Mid(LDevModeExtra, 1, 94) = LDevString.RGB
        LRpt.PrtDevMode = LDevModeExtra

    End If

    'Save report changes (suppress system messages temporarily)
    DoCmd.SetWarnings False
    DoCmd.Save acReport, pReport
    DoCmd.Close acReport, pReport
    DoCmd.SetWarnings True

    Exit Sub

Err_Execute:
    MsgBox "Changing paper size to legal failed."
End Sub

But it doesn't work at all, i.e. when I call SettoA3 procedure nothing happen.

Why not?


Well... I don't believe you wrote that code your self (a link to where you found it would have been helpful, I found about 20 references to it) but you probably want to change LDM.intPaperSize = 256 to LDM.intPaperSize = acPRPSA3.

I found this on MS's page (it's hidden in the dropdown for AcPrintPaperSize

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜