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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my forms automaticaly return to default settings, how can I stop this? 5

Status
Not open for further replies.

Phideaux

Technical User
May 1, 2003
51
0
0
US
my forms margins and paper selections return to the default settings at irregular intervals how can i stop this??
 
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:

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
 
Reread my post and realized I left something out...

Substitute Form each place I used Report, even in the code.

While I AM using the code with reports, I'm pretty sure it will work with forms that are printed, also.

Good Luck!
Bob
 
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!

Thanks again,

James Hardiman, JamesH@sunsail.com
 
James,

I hope (and believe) your problem will be fixed.

And THANK YOU for the star - my first!

Bob
 
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

Set rpt = Reports(strName)
rpt.Width = 60.96 * (1440 / 25.4)

PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.intBotMargin = 0 * (1440 / 25.4)
PM.intTopMargin = 15.91 * (1440 / 25.4)
PM.intLeftMargin = 7.2 * (1440 / 25.4)
PM.intRightMargin = 7.2 * (1440 / 25.4)
PM.intColumns = 3
PM.intRowSpacing = 0
PM.intColumnSpacing = 4.74 * (1440 / 25.4)
PM.intWidth = 6.095 * (1440 / 25.4)
PM.intHeight = 38.1 * (1440 / 25.4)
PM.intDataOnly = 0
PM.intDatasheet = 1
PM.intDefaultSize = 1
PM.intFastPrint = 1
PM.intItemLayout = 1953
LSet PrtMipString = PM
rpt.PrtMip = PrtMipString.strRGB

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.
 
You are most welcome, EvilaJC!

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.

Good luck!
Bob
 
EvilaJC,

Looking at the VB help "PaperSize" list:

Letter size setting is "intPaperSize As Integer" = 1

Legal size setting is "intPaperSize As Integer" = 5

Bob
 
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?

Thanks for any help.
 
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

Regards,

James Hardiman
 
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?


Thanks
 
In access, go to the database window, click modules, click New, and put that great long slew of code that's several appends above here.

Save it, call it what you like.

Have a report, and call it from a button on a form, using the code I appended last time.

James
 
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

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

on the print preview button I have the following code:

Private Sub btnMasterPreview_Click()
On Error GoTo Err_btnMasterPreview_Click

DoCmd.Requery
DoCmd.OpenReport "rptqryMasterAttendanceRosterAll", acViewPreview

Exit_btnMasterPreview_Click:
Exit Sub

Err_btnMasterPreview_Click:
MsgBox Err.Description
Resume Exit_btnMasterPreview_Click

End Sub


How does it know to use the module I just made?
 
In your code, it doesn't.

You've missed out the vital bits of my code...routine ShowLabelsReport in the module, and the code that calls ShowLabelsReport on the command button.
 
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?

Thanks for all your help.
 
Guess so.

You're into playing with it and trying it out now.

Append your code here for others when you get it to work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top