Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Margins

Status
Not open for further replies.

lordrich

IS-IT--Management
Jul 7, 2003
22
0
0
GB
When running our access database reports under access 97, the print margins were zero, and it fitted in the pre-printed paper perfectly.

Since upgrading to access 2000, we can no longer change the print margins to anything less than 6.35mm. Any attempts to do so appear to be saved, but whenever you go back into page setup it reverts back.

According to Microsoft Knowledge Base article Q282364, this is a design feature in Access 2002 and there is no advice on how to solve it.

If it worked fine in 97, surely there is a way to do it in 2000? Downgrading is no longer an option, as the database can not be converted back to the formats required for 97.
 
It may be a printer driver issue since 282364 states setting the margin to 0 results in Windows setting the margin to the lowest value the printer supports...

You can also set it at run time in VBA code. This can be useful when different printers are used and their non-printable margin widths are different.

Following is a way to set margins and orientation at run time.

Example code behind a Print Preview command button:

Private Sub RunPreviewReport_Click()

DoCmd.SetWarnings False
Call SetMargins("rptName", 0.5, 0.5, 0.5, 0.5)
'--ALL MARGINS 1/2 INCH
Call SetOrientation("rptName", True)
'--TRUE = PORTRAIT, FALSE = LANDSCAPE
DoCmd.Close acReport, "rptName", acSaveYes

DoCmd.SetWarnings True
DoCmd.OpenReport "rptName", acViewPreview
End Sub

VBA module:

Option Compare Database
Option Explicit

'--FOLLOWING USED TO SET PRINT ORIENTATION AND MARGINS AT RUN TIME, ENSURING CONSISTENCY

Type str_PRTMIP
strRGB As String * 28
End Type

Type type_PRTMIP
intLeftMargin As Long
intTopMargin As Long
intRightMargin As Long
intBotMargin As Long
intDataOnly As Long
intWidth As Long
intHeight As Long
intDefaultSize As Long
intColumns As Long
intColumnSpacing As Long
intRowSpacing As Long
intItemLayout As Long
intFastPrint As Long
intDatasheet As Long
End Type

Type str_DEVMODE
RGB As String * 94
End Type

Type type_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

Public Sub SetMargins(strName As String, sngLeft As Single, sngRight As Single, sngTop As Single, sngBottom As Single)
'-------------------------------
' strName = Report name
' sngLeft = Left Margin (in inches)
' sngRight = Right Margin
' sngTop = Top Margin
' sngBottom = Bottom Margin
'-------------------------------

Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report

DoCmd.OpenReport strName, acDesign
Set rpt = Reports(strName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.intLeftMargin = sngLeft * 1440
PM.intTopMargin = sngTop * 1440
PM.intRightMargin = sngRight * 1440
PM.intBotMargin = sngBottom * 1440
LSet PrtMipString = PM
rpt.PrtMip = PrtMipString.strRGB

End Sub

Public Sub SetOrientation(strName As String, boolPortrait As Boolean)
'-----------------------------
' strName = Report Name
' boolPortrait = Boolean...true = portrait, false = landscape
'-----------------------------

Const DM_PORTRAIT = 1
Const DM_LANDSCAPE = 2
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim rpt As Report
DoCmd.OpenReport strName, acDesign
Set rpt = Reports(strName)
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
If boolPortrait Then
DM.intOrientation = DM_PORTRAIT
Else
DM.intOrientation = DM_LANDSCAPE
End If
LSet DevString = DM
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
End Sub


HTH,
Bob
Your mileage may vary, but following the guidelines in faq181-2886 will help you reach your goal.
 
That code didn't work. It brings up the report in design view, and then when you go to print preview it still has the large margins.
I can't see it being a printer driver issue if it worked fine on access 97 on the same computer.
 
You might try

DoCmd.SetWarnings True

before Call SetMargins etc

to see if an error is reported.

The code does work for others, as evidenced by
thread702-560490

Good Luck,
Bob
 
Warnings turned on, code to set print margins moved to the form's onload rather than trying to do it at the same time as other fancy filters on the print preview button.

However, there are no warnings produced, and the margins still won't go any lower. Which would lead me to assume it's an issue with the print driver, except it did work fine in access 97.
 
If you're using Access 2000, did you disable Name Autocorrect?

From Microsoft Knowledgebase article 240826:


To avoid this problem, disable Name AutoCorrect by following these steps:
On the Tools menu, click Options.
In the Options dialog box, click the General tab.
Click to clear the Perform name AutoCorrect check box.
Click OK.
Quit and then restart Access

HTH,
Bob
Your mileage may vary, but following the guidelines in faq181-2886 will help you reach your goal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top