By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,761 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,761 IT Pros & Developers. It's quick & easy.

Controlling Paper Size

P: n/a
I got the following code from an earlier posting (much earlier, like 1999)
in this ng. This is supposed to control the paper size selected to legal,
even if the default printer changes. Question is where do I stick this code,
so that my calling function can see it? In the form from which I print the
report?

TIA.

Brian
Option Compare Database
Option Explicit

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 SwitchtoLegal(strName As String)
' Comments : Switches paper size to legal, regardless of original
setting
' Parameters : strName - contains the name of the report
' Returns : Saves report with new legal setting. User needs mod perm
' Created : Received from Brian Ward, 3/12/1999
' Modified : Kim Jacobson 3/12/1999
'
' --------------------------------------------------------
'Call the procedure like this:

' Dim strDocName As String

' strDocName = "Report Name Here"
' SwitchtoLegal (strDocName)

' --------------------------------------------------------
On Error GoTo Err_SwitchtoLegal
Dim DevString As gtypStr_DEVMODE
Dim DM As gType_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
DoCmd.Echo False, "Checking default printer settings..."
DoCmd.OpenReport strName, acDesign ' Opens report in Design
view.
Set rpt = Reports(strName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.intPaperSize = 5 'set to legal, standard would be 1
'DM.lngFields = DM.lngFields Or DM.intOrientation ' Initialize
fields.
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.SetWarnings False
DoCmd.Save acReport, strName
DoCmd.Close acReport, strName
DoCmd.SetWarnings True
DoCmd.Echo True, ""

Exit_SwitchtoLegal:
Exit Sub

Err_SwitchtoLegal:
DoCmd.Echo True, ""
Select Case Err
Case Else
msgbox Err & ":" & Err.Description, vbInformation + vbOKOnly,
"SwitchtoLegal"
Resume Exit_SwitchtoLegal
End Select
End Sub


Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Brian DSouza" <no****@nospam.net> wrote in message
news:-J********************@comcast.com...
I got the following code from an earlier posting (much earlier, like 1999)
in this ng. This is supposed to control the paper size selected to legal,
even if the default printer changes. Question is where do I stick this code, so that my calling function can see it? In the form from which I print the
report?

TIA.

Brian
Brian, you could put it in the module for the form, but that probably
wouldn't be the best place for it. In the future you might wish to open the
report elsewhere, or you might wish to use the same procedure for another
report. It would probably be better to simply put it into a standard module
(the module name doesn't matter). Simply call the routine from the form, as
shown in the example provided with the code.
' strDocName = "Report Name Here"
' SwitchtoLegal (strDocName)


Nov 12 '05 #2

P: n/a
That is what I thought. I stuck it in a module I call Globals, where I also
declare variables that I use for "global" system state information. I got
some kind of error message like.

"Function not defined."

and in the debug window:

<highlighted> SwitchtoLegal </highlighted>

I have made absolutely sure that the spelling is the same.

"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Kd********************@newssvr28.news.prodigy .com...
"Brian DSouza" <no****@nospam.net> wrote in message
news:-J********************@comcast.com...
I got the following code from an earlier posting (much earlier, like 1999) in this ng. This is supposed to control the paper size selected to legal, even if the default printer changes. Question is where do I stick this code,
so that my calling function can see it? In the form from which I print the report?

TIA.

Brian


Brian, you could put it in the module for the form, but that probably
wouldn't be the best place for it. In the future you might wish to open

the report elsewhere, or you might wish to use the same procedure for another
report. It would probably be better to simply put it into a standard module (the module name doesn't matter). Simply call the routine from the form, as shown in the example provided with the code.
' strDocName = "Report Name Here"
' SwitchtoLegal (strDocName)


Nov 12 '05 #3

P: n/a
"Brian DSouza" <no****@nospam.net> wrote in
news:1d********************@comcast.com:
That is what I thought. I stuck it in a module I call
Globals, where I also declare variables that I use for
"global" system state information. I got some kind of error
message like.

"Function not defined."

and in the debug window:

<highlighted> SwitchtoLegal </highlighted>

I have made absolutely sure that the spelling is the same.
In the module created find the line:
Sub SwitchtoLegal(strName As String)

Put the word public before it, eg Public Sub.....

Bob Q.
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:Kd********************@newssvr28.news.prodigy .com...
"Brian DSouza" <no****@nospam.net> wrote in message
news:-J********************@comcast.com...
> I got the following code from an earlier posting (much
> earlier, like 1999) > in this ng. This is supposed to control the paper size
> selected to legal, > even if the default printer changes. Question is where do I
> stick this

code,
> so that my calling function can see it? In the form from
> which I print the > report?
>
> TIA.
>
> Brian


Brian, you could put it in the module for the form, but that
probably wouldn't be the best place for it. In the future
you might wish to open

the
report elsewhere, or you might wish to use the same
procedure for another report. It would probably be better to
simply put it into a standard

module
(the module name doesn't matter). Simply call the routine
from the form,

as
shown in the example provided with the code.
> ' strDocName = "Report Name Here"
> ' SwitchtoLegal (strDocName)




Nov 12 '05 #4

P: n/a
Hi Brian,

This code appears to be essentially the same as that shown in a Microsoft KB article:

"ACC2000: How to Build a Visual Basic Module to Print a Report in Landscape Mode on
Legal-Size Paper"
http://support.microsoft.com/default.aspx?scid=kb;[LN];302416

I copied the code you included into a new module in the sample Northwind database. Then I
entered the following command into the debug window:

SwitchtoLegal("Alphabetical List of Products")

It works fine *most* of the time. However, sometimes I am receiving error # 29068, which
reads:
"Microsoft Access cannot complete this operation.
You must stop the code and try again".

When I stepped through the procedure line-by-line, I find that on those times when I get
the error, it consistently occurs on the line of code that reads:

DoCmd.Save acReport, strName

I'm kind of stumped as to why this error is not consistent--it's rearing its ugly head
just every so often.
Tom

____________________________________________

"Brian DSouza" <no****@nospam.net> wrote in message
news:-J********************@comcast.com...
I got the following code from an earlier posting (much earlier, like 1999)
in this ng. This is supposed to control the paper size selected to legal,
even if the default printer changes. Question is where do I stick this code,
so that my calling function can see it? In the form from which I print the
report?

TIA.

Brian
Option Compare Database
Option Explicit

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 SwitchtoLegal(strName As String)
' Comments : Switches paper size to legal, regardless of original
setting
' Parameters : strName - contains the name of the report
' Returns : Saves report with new legal setting. User needs mod perm
' Created : Received from Brian Ward, 3/12/1999
' Modified : Kim Jacobson 3/12/1999
'
' --------------------------------------------------------
'Call the procedure like this:

' Dim strDocName As String

' strDocName = "Report Name Here"
' SwitchtoLegal (strDocName)

' --------------------------------------------------------
On Error GoTo Err_SwitchtoLegal
Dim DevString As gtypStr_DEVMODE
Dim DM As gType_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
DoCmd.Echo False, "Checking default printer settings..."
DoCmd.OpenReport strName, acDesign ' Opens report in Design
view.
Set rpt = Reports(strName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.intPaperSize = 5 'set to legal, standard would be 1
'DM.lngFields = DM.lngFields Or DM.intOrientation ' Initialize
fields.
LSet DevString = DM ' Update property.
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.SetWarnings False
DoCmd.Save acReport, strName
DoCmd.Close acReport, strName
DoCmd.SetWarnings True
DoCmd.Echo True, ""

Exit_SwitchtoLegal:
Exit Sub

Err_SwitchtoLegal:
DoCmd.Echo True, ""
Select Case Err
Case Else
msgbox Err & ":" & Err.Description, vbInformation + vbOKOnly,
"SwitchtoLegal"
Resume Exit_SwitchtoLegal
End Select
End Sub

Nov 12 '05 #5

P: n/a
Bob Quintal <bq******@generation.net> wrote in message news:<96******************************@news.terane ws.com>...
"Brian DSouza" <no****@nospam.net> wrote in
news:1d********************@comcast.com:
That is what I thought. I stuck it in a module I call
Globals, where I also declare variables that I use for
"global" system state information. I got some kind of error
message like.

"Function not defined."

and in the debug window:

<highlighted> SwitchtoLegal </highlighted>

I have made absolutely sure that the spelling is the same.

In the module created find the line:
Sub SwitchtoLegal(strName As String)

Put the word public before it, eg Public Sub.....

Bob Q.


Thanks Bob, but I did that too, actually. Same error message. Very
strange. Any other ideas.
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.