Setting Print Margins

S

Steve Wright

Access seems to reset the print margins at random.

I am looking for a way to set the margins when a form is opened.

I assume that I need an On Open Event Proceedure and have written some code
based on the stuff contained in the Access
Help file but it refuses to run and gives the following error message.

The expression On Open you entered as the event property setting
produced the following error: Cannot define a
public user-defined type within an object Module.

* The expression may no result in the name of a macro, the name of a
user-defined function, or [Event Proceedure].
* There may have been an error evaluation the function, event, or
macro.

Can some one help me out please?

Code follows
=========================================================
Option Compare Database
Option Explicit
Type str_PRTMIP
strRGB As String * 28
End Type
Type type_PRTMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
End Type

Private Sub Form_Open(Cancel As Integer)
SetMarginsToDefault "F001 Carriageway Records" 'Name of the form
End Sub
Public Sub SetMarginsToDefault(strName As String)
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
DoCmd.OpenForm strName, acDesign
Set rpt = Forms(strName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.intLeftMargin = 0.3937 * 1440 ' Set margins. This gives 10mmm I
think
PM.intTopMargin = 0.3937 * 1440
PM.intRightMargin = 0.3937 * 1440
PM.intBotMargin = 0.3937 * 1440
LSet PrtMipString = PM ' Update property.
rpt.PrtMip = PrtMipString.strRGB
' probably not needed if this runs every time the form is opened
'DoCmd.Close acForm, strName, acSaveYes

End Sub
============================================================
 
A

Allen Browne

The problem of reports that do not hold their margins can be traced to Name
AutoCorrect. See:
Lost Printer Settings When Name AutoCorrect Is Enabled
at:
http://support.microsoft.com/?id=240826

Turn off Name AutoCorrect. Compact the database.
Open your report in design view, and save the correct margins.
There are more than a dozen other bugs associated with Name AutoCorrect
also:
http://allenbrowne.com/bug-03.html

Actually, just noticed you are printing a form, not a report. Would you
consider saving the form as a report, and then printing that? It gives you
much more control over the printing layout, and avoids messing with PrtMip.
That's just a matter of selecting your form in the Database window, and
choosing Save As.

It's not easy to get PrtMip right. Microsoft got their example wrong in the
Help files of Access 95, 97, and 2000, in different places. I haven't
checked the more recent versions, but the knowledgebase/msdn articles have
it right.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Steve Wright said:
Access seems to reset the print margins at random.

I am looking for a way to set the margins when a form is opened.

I assume that I need an On Open Event Proceedure and have written some code
based on the stuff contained in the Access
Help file but it refuses to run and gives the following error message.

The expression On Open you entered as the event property setting
produced the following error: Cannot define a
public user-defined type within an object Module.

* The expression may no result in the name of a macro, the name of a
user-defined function, or [Event Proceedure].
* There may have been an error evaluation the function, event, or
macro.

Can some one help me out please?

Code follows
=========================================================
Option Compare Database
Option Explicit
Type str_PRTMIP
strRGB As String * 28
End Type
Type type_PRTMIP
xLeftMargin As Long
yTopMargin As Long
xRightMargin As Long
yBotMargin As Long
End Type

Private Sub Form_Open(Cancel As Integer)
SetMarginsToDefault "F001 Carriageway Records" 'Name of the form
End Sub
Public Sub SetMarginsToDefault(strName As String)
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
DoCmd.OpenForm strName, acDesign
Set rpt = Forms(strName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.intLeftMargin = 0.3937 * 1440 ' Set margins. This gives 10mmm I
think
PM.intTopMargin = 0.3937 * 1440
PM.intRightMargin = 0.3937 * 1440
PM.intBotMargin = 0.3937 * 1440
LSet PrtMipString = PM ' Update property.
rpt.PrtMip = PrtMipString.strRGB
' probably not needed if this runs every time the form is opened
'DoCmd.Close acForm, strName, acSaveYes

End Sub
============================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top