Sounds like you may be selecting different printers. I'm assuming here, but I reckon that you're changing Printer Drivers and that could be cause of your problem.
I suppose you could try hard-coding the relevent form properties into it's OnLoad event, but it's not the best solution. You'd have to give me a bit more info about the problem.
Access reports save margin and portrait/landscape settings used the last time the report was produced. Those settings may have been changed due to hardware limitations or the default settings of the PC used to create the report. Or by user selection if you allow it. They will be used the next time the report is produced unless they must be changed TO LARGER MARGINS for the current hardware or defaults.
This is supposed to be a good thing as it facilitates portability between printers. You decide if it's worth it.
This usually means that someone produced the report with their Access default margins set to 1" all around. (That's the Access install default.) Then when you run it on your PC, those margins are acceptable and are USED instead of your default margins of, for example, .5" all around. At least that's what happened to me.
I'm trying to say this so it makes sense...
In short, margins of .5" cannot be enforced if the hardware or defaults when run require 1". However, if the report WAS previously run with margins of 1", that CAN and WILL be maintained the next time the report is run even if the hardware/defaults allow smaller margins.
Access makes sure that larger margin requirements are honored, but does not automatically resize for smaller margin capabilities.
If you want to force the settings you must do it in code.
This is documented in a Microsoft Knowledgebase article, but I cannot immediately find the number.
You'll need to create a VBA module and add event code for the report.
Good Luck!
Bob
P.S. This comes with my infamous 30/30 guarantee...
30 seconds/30 feet - whichever comes first.
Seriously, this is used live on a daily basis in my site.
Example code behind a Print Preview command button:
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
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
WoW! Thanks, Bob Jackson. I'm responsible for an Access ADP which is shipped out to our clubs in Turkey and (next year) Greece.
Every club has different printers (and all different from the one I use here).
My app has a number of reports that produce labels. I get them all set up beautifully here, then ship the app to the clubs, and they moan that the labels don't print properly.
I think your code may have solved my problem, after only three years of looking!
In case anyone else has the "labels" problem, here are the routines that I added to Bob's module code above:
I know all the 1440/25.4 is a bit messy--I was in a hurry, and needed to work in millimetres rather than inches or twerps or whatever!
BTW, I've no idea what:
PM.intItemLayout = 1953
does -- I looked at the settings of a report that worked, and copied them over!
Public Sub SetLabels(strName As String)
'-----------------------------
' strName = Report Name
' This makes sure that the report is correctly set up to print Avery A4 L7160 labels
' (7 rows, 3 columns, 60.95mm x 38.1 mm
'-----------------------------
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
DoCmd.OpenReport strName, acDesign
If Not IsNull(rpt.PrtDevMode) Then
strDevModeExtra = rpt.PrtDevMode
DevString.RGB = strDevModeExtra
LSet DM = DevString
DM.intOrientation = 1 ' PORTRAIT
DM.intPaperSize = 9 ' A4
LSet DevString = DM
Mid(strDevModeExtra, 1, 94) = DevString.RGB
rpt.PrtDevMode = strDevModeExtra
End If
DoCmd.Close acForm, strName, acSaveYes
End Sub
Public Sub ShowLabelsReport(strName As String, strFilter As String)
SetLabels strName
DoCmd.Close acReport, strName, acSaveYes
DoCmd.OpenReport strName, acViewPreview, , strFilter
End Sub
Thanks, BobJacksonWcom, for the great script. That also took care of a problem I had on one of my databases. I noticed on the module end that it was possible to force legal and/or letter paper. How would I go about doing this?
My database is shared using Terminal Server (don't ask me why-- this was just the cannister I was given to work in), and everytime a user connects, their printers are grabbed at the letter/portrait/1-inch margin default, regardless of how the original reports are set up. Since we have legal- as well as letter-sized reports, that legal/letter tool would be greatly appreciated.
I don't have the Access experience to answer your question confidently regarding setting the form length. I originally posted a reply here to help a fellow Access'er with what I'd found. I.E., my solution was a cut-and-paste borrowed from another source. I recommend that you open Visual Basic help and use the Answer Wizard with the following:
"PrtDevMode Property or PrtMip Property"
When "PrtDevMode Property" is on your monitor, look at "PaperSize" and the hotlink to "PaperSize member values"
Note: You cannot change these properties at run time if you are using .MDE databases.
That is explained in Microsoft's knowledge base, article 209867. You may want to look at that, also.
Just a starting point, but hopefully you can resolve your issue.
Hi,
I am trying to use the code but not to sure were to put it.
I have a utility module that has different functions in it would it go there or does the code have to go on every report?
I put all that code in an Access module, and then this is behind a button on a form:
Private Sub cmdPrintLabels_Click()
If cmbAreaFilter = "Bar" Then
ShowLabelsReport "rptProductListBarLabels", Me.Filter
Else
ShowLabelsReport "rptProductListNonBarLabels", Me.Filter
End If
End Sub
Thanks for the quick reply, Still thick here, If I have all the code listed in this thread do i make a new module and name it something?
or is all the code put in each form that needs to printing.
I have called functions before is it the same?
in the code you just replied with where does that call the setlabels code.
Is there a module that every form can see and it is loaded every time the database is?
Still don't work, I must not see the forest through the trees.
I made a new module and pasted the following code into it and called the module printreport:
Option Compare Database
Option Explicit
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, AsSingle, 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
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
on the print preview button I have the following code:
Private Sub btnMasterPreview_Click()
On Error GoTo Err_btnMasterPreview_Click
thanks, I was wondering about that.LOL
If i change the margin settings your code will work for a full page also? And what if I wanted different margins on different reports. Would I set up a variable for the different entrys. ie "PM.intRightMargin = rmar" of course dim the rmar and then on the criteria of the openreport on the button pass the numbers I want?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.