Application.Printer object and Access 2000

P

paul.m.henderson

Hi,

We've recently added some functionality using the application.printer
object, however, as it turns out this does not work in Access 2000. Is
there any way that we can keep this code in the application, but tell
the compiler to ignore it? We're trying to avoid having a separate
copy of the application just for Access 2000 users. Any thoughts?
Thanks!
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top