programmatically set up a report so that it will print on legal size paper (ie: 8.5 x

china99boy

Registered User.
Local time
Today, 08:13
Joined
Apr 27, 2006
Messages
161
Ok I found this code online, but I am not the smartest person in the world. I have create a module and insert this code in it. Then it states that I should call this subroutine. I am not sure how this will set the report to print on legal paper. I am not sure how this is suppose to play out. Exactly where do I put this subroutine?

Private Sub Command0_Click()

SetToLegal "Report1"

End Sub


This code was inserted into a module:

Type gtypStr_DEVMODE
RGB As String * 94
End Type

Type gType_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 SetToLegal(pReport As String)

Dim LDevString As gtypStr_DEVMODE
Dim LDM As gType_DEVMODE
Dim LDevModeExtra As String
Dim LRpt As Report

On Error GoTo Err_Execute

'Open report in Design view
DoCmd.OpenReport pReport, acDesign
Set LRpt = Reports(pReport)

'Change paper size to legal
If Not IsNull(LRpt.PrtDevMode) Then

LDevModeExtra = LRpt.PrtDevMode
LDevString.RGB = LDevModeExtra
LSet LDM = LDevString

'5=legal, 1=standard
LDM.intPaperSize = 5
LSet LDevString = LDM
Mid(LDevModeExtra, 1, 94) = LDevString.RGB
LRpt.PrtDevMode = LDevModeExtra

End If

'Save report changes (suppress system messages temporarily)
DoCmd.SetWarnings False
DoCmd.Save acReport, pReport
DoCmd.Close acReport, pReport
DoCmd.SetWarnings True

Exit Sub

Err_Execute:
MsgBox "Changing paper size to legal failed."
End Sub
 
Well, that's a giant overkill if I've ever seen one. In the Report's Open event, just use this:

Me.Printer.PaperSize = acPRPSLegal

That's it. To see all the printer properties you can assign, open any report in design mode, go to the code window for that report and then to the Report Open Event (create it if it isn't there), and type Me.Printer. followed by nothing. IntelliSense will show you all the properties and methods available for changing paper trays, print quality, etc.
 
LOL, This is why I love this forum. People helping people. I did mention, I wasn't the smartest. Thank you for that information.
 

Users who are viewing this thread

Back
Top Bottom