访问问题:如何通过VBA代码设置访问报告纸张尺寸A3

时间:2011-06-03 15:29:38

标签: ms-access ms-access-2010

每当用户通过VBA打印时,我都希望将访问报告纸张大小永久设置为A3 代码。 为此我写了这个我在网上找到的代码

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 gType_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

但它根本不起作用,即当我调用SettoA3程序时没有任何事情发生。

为什么不呢?

1 个答案:

答案 0 :(得分:0)

嗯......我不相信你自己写了那段代码(你找到它的链接会有所帮助,我找到了大约20个引用)但你可能想要改变LDM.intPaperSize = 256LDM.intPaperSize = acPRPSA3

我在MS's page上找到了这个(它隐藏在AcPrintPaperSize的下拉列表中