程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> 關於Access數據庫 >> Access2003中自動完成報表的頁面設置

Access2003中自動完成報表的頁面設置

編輯:關於Access數據庫
使用過Access 2003報表的用戶會發現一個問題,報表的頁邊距在設計時往往事先已經設計好,預覽打印都很正常,但當下次再預覽或打印時就會發現報表的頁邊距不正常了,這主要是由於在Access2003中頁面設置在設計時的參數不能很好的保留,造成了今後使用報表時出現頁邊距不理想的狀況,能否利用VBA程序的方法讓報表的頁邊距自動控制,而無需人工來再次進行頁面的設置。

    這裡給出一個過程,利用這個過程,在打印報表時會自動按照定義的頁面參數進行頁面的自動設置。

    將下面的過程放在模塊中,使用時只需調用這個過程即可進行報表頁面的自動設置。

調用方法:

Setprint(報表名稱,方向,上邊距,下邊距,左邊距,右邊距)。

'例:設置縱向打印 Setprint("銷售報表", 1, 20, 10, 20, 10)
'例:設置橫向打印 Setprint("銷售報表", 0, 20, 10, 20, 10) 

Option Compare Database
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


'以下過程用來進行報表頁面自動設置,過程所帶參數為(報表名稱,方向,上邊距,下邊距,左邊距,右邊距)。
'例:設置縱向打印 Setprint("銷售報表", 1, 20, 10, 20, 10)
'例:設置橫向打印 Setprint("銷售報表", 0, 20, 10, 20, 10)
Sub Setprint(strName, fx, sbj, xbj, zbj, ybj)
    Const DM_PORTRAIT = 1
    Const DM_LANDSCAPE = 2
    Dim DevString As str_DEVMODE
    Dim dm As type_DEVMODE
    Dim PrtMipString As str_PRTMIP
    Dim PM As type_PRTMIP
    Dim strDevModeExtra As String
    Dim rpt As Report
    ' Opens report in Design vIEw.
    DoCmd.OpenReport strName, acDesign
    Set rpt = Reports(strName)
    PrtMipString.strRGB = rpt.PrtMip
    LSet PM = PrtMipString
    PM.yTopMargin = sbj * 1440 * 0.0394    ' 設置上邊距。
    PM.yBotMargin = xbj * 1440 * 0.0394    ' 設置下邊距。
    PM.xLeftMargin = zbj * 1440 * 0.0394   ' 設置左邊距。
    PM.xRightMargin = ybj * 1440 * 0.0394  ' 設置右邊距。
    LSet PrtMipString = PM            ' 更新屬性。
    rpt.PrtMip = PrtMipString.strRGB
    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 fx = 1 Then
         dm.intOrIEntation = DM_PORTRAIT '設置縱向打印
        Else
         dm.intOrIEntation = DM_LANDSCAPE '設置橫向打印
        End If
        LSet DevString = dm            ' Update property.
        Mid(strDevModeExtra, 1, 94) = DevString.RGB
        rpt.PrtDevMode = strDevModeExtra
    End If
    DoCmd.Save acReport, strName
    Set rpt = Nothing
    On Error GoTo err1
     DoCmd.OpenReport strName, acViewPrevIEw
err1:
End Sub

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved