Unfortunately, No.
VB has a printer object, that allows you to manipulate the properties of
any of the installed printers (using a Set Printer = <printer object>
command). MS-Access VBA does not support this object.
However, what you can do, is re-create the report at design time, you can
specify whether it is a portrait or landscape report. To do this, simply:
Choose the report to change to Landscape
Click on Design
Choose Print Setup (under the File Menu)
In the Orientation box, choose Landscape
Choose OK
Save the design
This has changed the report layout to landscape, ONLY for that report (it
is not the default for all reports).
When you design a report, it takes the default layout from the systems
default printer setup. Changing it at the report design stage, assigns the
new properties (including a different printer, if you select it) to that
report only. Be careful doing this, as you may have access to a printer
that others do not, so when they try to print the report, they may get an
error.
Hope this helps.
Bas van Dijk <bvan...@worldonline.nl> wrote in article
<6vdpsi$bf4$2...@news.worldonline.nl>...
> Hi all,
>
> Is it possible (and easy?) to set the printer option to 'landscape'
> for a report but back to 'portrait' when the report is closed?
> (I mean automatically when the report opens, for example with
> a VBA routine)
>
> Thanks,
> Bas
>
>
>
Here's what I do. This code is for 8.0. It will work in 2.0 if you tweak
the deviceModeStructure. If someone has a better way, I'd sure like to hear
about it.
=================================
'------------------------------------------------------------------------
' These two types support our access to a report's prtDevMode property.
' They were cloned from the "zwAllGlobals" module of allWZFRMRPT.MDA and
' are used in reportPrintOne()
Type deviceModeString
dmStringValue As String * 512
End Type
Global Const gOrientationChanged = &H1
Global Const gPaperSizeChanged = &H2
Global Const gCopiesChanged = &H100
Global Const gYieldHistoryDataEntryWorkTableName = "zstblYieldHistoryDataEntry"
Type deviceModeStructure
dmDeviceName As String * 32
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long 'Orientation = &H1, PaperSize = &H2,
Copies = &H100
dmOrientation As Integer 'Portrait = 1, Landscape = 2
dmPaperSize As Integer 'Letter = 1 Legal = 5
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmResolution As Integer
dmTTOption As Integer
dmFiller As String * 444
End Type
Type fv_FileInfoBuffer
Item As String * 1024
End Type
Function reportPrintOne(theReportName As Variant, thePrintMode As Integer,
theCriteria As String, theNumberOfCopies As Integer, thePaperSize,
theOrientation) As Integer
7000 debugStackPush "basUtility: reportPrintOne"
7001 On Error GoTo reportPrintOne_err
' This function is necessitated by Access/NT's habit of changing printer
setup when the user's
' default printer matches assigned specific printer. Unfortunately when
this happens,
' the paper size and orientation get reset to the printer's default.
' Sounds harmless, but unfortunately the paper size also gets changed to the
default
' paper size for the printer - which is letter.
' What we're doing here is opening the report in design mode, forcing it's
paper size to
' legal, saving it (so the user doesn't get prompted "Save changes to this
report..."
' and then printing the report.
7005 Dim myDevString As deviceModeString
Dim myDevStruct As deviceModeStructure
Dim myReport As Report
Dim myTempString As String
Dim myReportName As String
Dim devName As String
Dim L As Integer
Dim x As Integer
Dim i As Integer
Dim skipLine As String
skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
Const notFound = 3078
Const userCancelled = 2501
7107 myReportName = theReportName
7008 If gUserUpdatePermission = True Then
7009 DoCmd.Echo False 'So user doesn't see report
in design mode
7010 DoCmd.OpenReport theReportName, A_DESIGN
7165 myReportName = theReportName
7012 Set myReport = Reports(myReportName)
7020 Reports(theReportName).Painting = False
7030 If Not IsNull(myReport.PrtDevMode) Then
7031 myTempString = myReport.PrtDevMode
7035 myDevString.dmStringValue = myTempString
7040 LSet myDevStruct = myDevString
7045 myDevStruct.dmOrientation = theOrientation
7050 myDevStruct.dmPaperSize = thePaperSize
7059 myDevStruct.dmFields = myDevStruct.dmFields Or gOrientationChanged Or
gPaperSizeChanged
7060 LSet myDevString = myDevStruct
7065 Mid$(myTempString, 1, 68) = myDevString.dmStringValue
7070 myReport.PrtDevMode = myTempString
7080 DoCmd.SetWarnings False
7090 DoCmd.DoMenuItem 7, A_FILE, 2 'Save the updated report
7100 DoCmd.SetWarnings True
7140 Else
7150 bugAlert True, "Null prtDevMode for: " & myReportName
7160 End If
7170 DoCmd.Close A_REPORT, myReportName
7175 DoCmd.Echo True
7176 End If
BypassPaperSetting:
7179 DoCmd.SetWarnings False
7200 If thePrintMode = A_PREVIEW Then 'Do what we came here to do:
just print the report...
7210 DoCmd.OpenReport myReportName, thePrintMode, , theCriteria
7220 Else
7230 For i = 1 To theNumberOfCopies
7240 DoCmd.OpenReport myReportName, thePrintMode, , theCriteria
7298 Next i
7299 End If
7182 DoCmd.SetWarnings True
7999 reportPrintOne = True
reportPrintOne_xit:
debugStackPop
On Error Resume Next
Exit Function
reportPrintOne_err:
reportPrintOne = False
Select Case Err
Case notFound
If gUserUpdatePermission Then
MsgBox "One or more work tables are missing:" & skipLine & Error, 48,
"Please Refresh Work Tables"
Else
MsgBox "One or more work tables are missing." & skipLine & "Your userID
does not have permission to refresh work tables." & skipLine & "Please ask
someone with update permission to refresh the work tables." & skipLine & Error,
48, "Cannot Run Report"
End If
Case userCancelled
MsgBox "Report Cancelled", 0, "Cancelled"
Case Else
bugAlert True, myReportName
End Select
Resume reportPrintOne_xit
End Function
=================================
-----------------------
Pete Cresswell
Is it possible (and easy?) to set the printer option to 'landscape'
for a report but back to 'portrait' when the report is closed?
This is intended to be used in an environment where each user is executing their
own copy of the front end DB.
I use a .BAT file to download the front end to each user's C: drive and refresh
the copy when I put out a new release of the front end. I do all my apps this
way and forgot about the implications of my code in some other environment...
I do not know exactly what the consequences would be if multiple users were
beating on the same copy of the front end using the code I posted - but I would
expect trouble....
-----------------------
Pete Cresswell
In article <6vdpsi$bf4$2...@news.worldonline.nl>,
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own