You can fool Access by declaring a really generic variable of type Object
instead of the more specific Form or Report variable.
Access 2000 knows that the Report does not have a Printer, but if you
declare Object it has know way to know what kind of properties and methods
the object might have. The example below shows how to call a generic
function to set the margins and orientation of a report in Access 2002 or
2003, but just ignore it if it is executed in Access 2000. To call the code
for a report named Report1, you would use:
DoCmd.OpenReport "Report1", acViewPreview
Call SetMarginsAndOrientation(Reports!Report1)
Note that the code uses the literal value for the orientation as well, since
the constant is not available in Access 2000.
Private Function SetMarginsAndOrientation(obj As Object) As Boolean
'Purpose: Set half-inch margins, and switch to landscape orientation.
'Argument: the report. (Object used, because Report won't compile in
early versions.)
'Return: True if set.
'Notes: 1. Applied in Access 2002 and later only.
' 2. Setting orientation in design view and then opening in
preview does not work reliably.
Const lngcMargin = 720& 'Margin setting in twips (0.5")
'Access 2000 and earlier do not have the Printer object.
If Int(Val(SysCmd(acSysCmdAccessVer))) >= 10 Then
With obj.Printer
.TopMargin = lngcMargin
.BottomMargin = lngcMargin
.LeftMargin = lngcMargin
.RightMargin = lngcMargin
.Orientation = 2 'acPRORLandscape not available in
A2000.
End With
'Return True if set.
SetMarginsAndOrientation = True
End If
End Function