這裡給出一個過程,利用這個過程,在打印報表時會自動按照定義的頁面參數進行頁面的自動設置。
將下面的過程放在模塊中,使用時只需調用這個過程即可進行報表頁面的自動設置。
調用方法:
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