468,321 Members | 1,797 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Printer Orientation and PrtDevMode MSDN example not working

Hi All,

I am using the PrtDevMode property of a report open in design view to
try and flip the orientation of the report between Portrait and
Landscape in a user control box before the report is opened. I pretty
much used the example out of the help verbatim and Im not having any
luck with it working. I thought originally that because some of my
controls (Lines) extended to the right margin of the report (designed
in Landscape) that Access wouldn't flip it. I shortened the controls
yet the page still always shows up in Landscape. Here is my code as it
stands.

Synopsis: Using an existing report template, I copy the template to a
new report name. Open the report in design view, set the printer
orientation, render some dynamic controls (columns), set the
recordsource, save the report and then open it in design mode.
On Error Resume Next
DoCmd.DeleteObject acReport, "_AutoReport"
On Error GoTo 0

DoCmd.CopyObject , "_AutoReport", acReport, "_SemiAnnualMaster"
DoCmd.OpenReport "_AutoReport", acViewDesign
Set rpt = Reports("_AutoReport")

rpt.RecordSource = ""

'Setup our printer page layout here
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.intOrientation = 1
LSet DevString = DM
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra

'Calculate our spacing on controls...
Dim lngWorkingSpace As Long
Dim lngColumnWidth As Long
Dim lngColumnCount As Long
lngWorkingSpace = rpt.Width - LEFT_DATA_MARGIN
lngColumnWidth = lngWorkingSpace / Me.AnalyteColumnCount

lngColumnCount = 1

If IsNumeric(Me.AnalyteColumnCount) Then
For i = 1 To Me.ColumnList.ListCount
If ColumnList.Column(3, i) = Me.ReportGroup Then
'create a label or possibly many
Dim Labels() As String
If IsNull(ColumnList.Column(4, i)) Then
Set ctlLabel = CreateReportControl(rpt.Name, acLabel,
acPageHeader, , , LEFT_DATA_MARGIN + ((lngColumnCount - 1) *
lngColumnWidth), 780 + (210), lngColumnWidth, 210)
ctlLabel.Caption = ColumnList.Column(0, i)
If Not IsNull(Me.ColumnAlignment) Then
ctlLabel.TextAlign = Me.ColumnAlignment
End If
Else
Labels = Split(ColumnList.Column(4, i), "<p>", ,
vbTextCompare)
For j = 0 To Database.GetUpper(Labels, 1) - 1
Set ctlLabel = CreateReportControl(rpt.Name,
acLabel, acPageHeader, , , LEFT_DATA_MARGIN + ((lngColumnCount - 1) *
lngColumnWidth), 780 + (210 * j), lngColumnWidth, 210)
ctlLabel.Caption = Labels(j)
If Not IsNull(Me.ColumnAlignment) Then
ctlLabel.TextAlign = Me.ColumnAlignment
End If
Next j
End If

'create a text box
Set ctlTextBox = CreateReportControl(rpt.Name, acTextBox,
acDetail, , ColumnList.Column(1, i), LEFT_DATA_MARGIN +
((lngColumnCount - 1) * lngColumnWidth), 0, lngColumnWidth, 210)
If Not IsNull(Me.DataFormat) And Me.DataFormat <> "" Then
ctlTextBox.Format = Me.DataFormat
End If
If Not IsNull(Me.ColumnAlignment) Then
ctlTextBox.TextAlign = Me.ColumnAlignment
End If
ctlTextBox.BorderStyle = 0
ctlTextBox.FontName = "Arial"
lngColumnCount = lngColumnCount + 1
End If
Next i
End If

rpt.RecordSource = strSQL

DoCmd.Close acReport, rpt.Name, acSaveYes
DoCmd.OpenReport "_AutoReport", acViewPreview

Any thoughts on which Access quirk is keeping this from flipping? thank
you much.

ja

Nov 13 '05 #1
2 4352
Try this :
http://msdn.microsoft.com/library/de...0_printers.asp
<je**@askey.org> a écrit dans le message de news:
11*********************@f14g2000cwb.googlegroups.c om...
Hi All,

I am using the PrtDevMode property of a report open in design view to
try and flip the orientation of the report between Portrait and
Landscape in a user control box before the report is opened. I pretty
much used the example out of the help verbatim and Im not having any
luck with it working. I thought originally that because some of my
controls (Lines) extended to the right margin of the report (designed
in Landscape) that Access wouldn't flip it. I shortened the controls
yet the page still always shows up in Landscape. Here is my code as it
stands.

Synopsis: Using an existing report template, I copy the template to a
new report name. Open the report in design view, set the printer
orientation, render some dynamic controls (columns), set the
recordsource, save the report and then open it in design mode.
On Error Resume Next
DoCmd.DeleteObject acReport, "_AutoReport"
On Error GoTo 0

DoCmd.CopyObject , "_AutoReport", acReport, "_SemiAnnualMaster"
DoCmd.OpenReport "_AutoReport", acViewDesign
Set rpt = Reports("_AutoReport")

rpt.RecordSource = ""

'Setup our printer page layout here
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.intOrientation = 1
LSet DevString = DM
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra

'Calculate our spacing on controls...
Dim lngWorkingSpace As Long
Dim lngColumnWidth As Long
Dim lngColumnCount As Long
lngWorkingSpace = rpt.Width - LEFT_DATA_MARGIN
lngColumnWidth = lngWorkingSpace / Me.AnalyteColumnCount

lngColumnCount = 1

If IsNumeric(Me.AnalyteColumnCount) Then
For i = 1 To Me.ColumnList.ListCount
If ColumnList.Column(3, i) = Me.ReportGroup Then
'create a label or possibly many
Dim Labels() As String
If IsNull(ColumnList.Column(4, i)) Then
Set ctlLabel = CreateReportControl(rpt.Name, acLabel,
acPageHeader, , , LEFT_DATA_MARGIN + ((lngColumnCount - 1) *
lngColumnWidth), 780 + (210), lngColumnWidth, 210)
ctlLabel.Caption = ColumnList.Column(0, i)
If Not IsNull(Me.ColumnAlignment) Then
ctlLabel.TextAlign = Me.ColumnAlignment
End If
Else
Labels = Split(ColumnList.Column(4, i), "<p>", ,
vbTextCompare)
For j = 0 To Database.GetUpper(Labels, 1) - 1
Set ctlLabel = CreateReportControl(rpt.Name,
acLabel, acPageHeader, , , LEFT_DATA_MARGIN + ((lngColumnCount - 1) *
lngColumnWidth), 780 + (210 * j), lngColumnWidth, 210)
ctlLabel.Caption = Labels(j)
If Not IsNull(Me.ColumnAlignment) Then
ctlLabel.TextAlign = Me.ColumnAlignment
End If
Next j
End If

'create a text box
Set ctlTextBox = CreateReportControl(rpt.Name, acTextBox,
acDetail, , ColumnList.Column(1, i), LEFT_DATA_MARGIN +
((lngColumnCount - 1) * lngColumnWidth), 0, lngColumnWidth, 210)
If Not IsNull(Me.DataFormat) And Me.DataFormat <> "" Then
ctlTextBox.Format = Me.DataFormat
End If
If Not IsNull(Me.ColumnAlignment) Then
ctlTextBox.TextAlign = Me.ColumnAlignment
End If
ctlTextBox.BorderStyle = 0
ctlTextBox.FontName = "Arial"
lngColumnCount = lngColumnCount + 1
End If
Next i
End If

rpt.RecordSource = strSQL

DoCmd.Close acReport, rpt.Name, acSaveYes
DoCmd.OpenReport "_AutoReport", acViewPreview

Any thoughts on which Access quirk is keeping this from flipping? thank
you much.

ja

Nov 13 '05 #2
That worked like a charm. Thank you. Much Much Easier than the 'old'
way.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bruce Adams | last post: by
3 posts views Thread by Rick Collard | last post: by
5 posts views Thread by Hank | last post: by
1 post views Thread by Karthic | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.