对了,我将出错过程说明一下:
我建了一个[模块1],使用的是帮助中的例子,不过做了两处调整:1,将Sub SwitchOrient(strName As String) 改为了函数:function SwitchOrient(strName As String) 2,将此过程中第一句:Const DM_PORTRAIT = 1 改为 ' Const DM_PORTRAIT = 1(即注释掉了)。 在调用此函数时,程序出现无反映现象,强行中止后就不能打开了! 还请各位高手们出手相助小弟一下!
模块1内容:
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
Sub CheckCustomPage(rptName As String)
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
Dim intResponse As Integer
' 在“设计”视图中打开报表。
DoCmd.OpenReport rptName, acDesign
Set rpt = Reports(rptName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
' 获取当前的 DEVMODE 结构。
DevString.RGB = strDevModeExtra
LSet DM = DevString
If DM.intPaperSize = 256 Then
' 显示用户自定义大小。
intResponse = MsgBox("The current " _
& "custom page size is " _
& DM.intPaperWidth / 254 _
& " inches wide by " _
& DM.intPaperLength / 254 _
& " inches long. Do you want " _
& "to change the settings?", 4)
Else
' Currently not user-defined.目前用户未自定义。
intResponse = MsgBox("The report " _
& "does not have a custom page " _
& "size. " _
& "Do you want to define one?", 4)
End If
If intResponse = 6 Then
' 用户需要更改设置。
' 初始化字段。
DM.lngFields = DM.lngFields Or _
DM.intPaperSize Or DM.intPaperLength _
Or DM.intPaperWidth
DM.intPaperSize = 256 ' Set custom page.
' 提示输入长和宽。
DM.intPaperLength = InputBox("lease enter page length " _
& "in inches.") * 254
DM.intPaperWidth = InputBox("lease enter page width " _
& "in inches.") * 254
LSet DevString = DM ' 更新属性。
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
End If
End Sub
function SwitchOrient(strName As String)
Const DM_PORTRAIT = 1
Const DM_LANDSCAPE = 2
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
' Opens report in Design view.
DoCmd.OpenReport strName, acDesign
Set rpt = Reports(strName)
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 DM.intOrientation = DM_PORTRAIT Then
DM.intOrientation = DM_LANDSCAPE
Else
DM.intOrientation = DM_PORTRAIT
End If
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
End function