This article was previously published under Q209867
Advanced: Requires expert coding, interoperability, and multiuser skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Option Explicit
Type str_PRTMIP
strRGB As String * 28
End Type
Type type_PRTMIP
lngLeftMargin As Long
lngTopMargin As Long
lngRightMargin As Long
lngBotMargin As Long
lngDataOnly As Long
lngWidth As Long
lngHeight As Long
lngDefaultSize As Long
lngColumns As Long
lngColumnSpacing As Long
lngRowSpacing As Long
lngItemLayout As Long
lngFastPrint As Long
lngDatasheet As Long
End Type
Private Sub Command0_Click()
' This example shows how to set report margins in a secured
' database.
Dim wrkAdmin As Workspace
Dim dbs As Database
Dim ctrReports As Container
Dim docReport As Document
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim Rpt As Report
Dim strName As String
strName = "Summary of Sales by Year"
' Create a new session and assign it to the database administrator.
Set wrkAdmin = DBEngine.CreateWorkspace("AdminWorkspace", "Admin", _
"Admin", dbUseJet)
' Be sure to change the path in this next line to match your path to
' Northwind.mdb.
Set dbs = wrkAdmin.OpenDatabase("C:\Northwind.mdb", False)
Set ctrReports = dbs.Containers!Reports
Set docReport = ctrReports.Documents(strName)
' Give the Users group full permissions to this report.
docReport.UserName = "Users"
docReport.Permissions = dbSecFullAccess
' Close the session.
wrkAdmin.Close
' Open the report in Design view and set the report object variable.
DoCmd.Echo False
DoCmd.OpenReport strName, acDesign
Set Rpt = Reports(strName)
' Assign the reports current device information.
PrtMipString.strRGB = Rpt.PrtMip
' Assign the device information into its various components.
LSet PM = PrtMipString
' The new margin settings to be used are half inch.
' Note: The Summary of Sales by Year report has 1" margins by
' default.
PM.lngLeftMargin = 0.5 * 1440
PM.lngTopMargin = 0.5 * 1440
PM.lngRightMargin = 0.5 * 1440
PM.lngBotMargin = 0.5 * 1440
' Update the device information with the new settings.
LSet PrtMipString = PM
Rpt.PrtMip = PrtMipString.strRGB
' Close the design of the report, saving the changes,
' and then preview the report.
DoCmd.Close acReport, strName, acSaveYes
DoCmd.OpenReport strName, acViewPreview
DoCmd.Echo True
' Re-create a new session, assigning it to the database
' administrator.
Set wrkAdmin = DBEngine.CreateWorkspace("AdminWorkspace", "Admin", _
"Admin", dbUseJet)
' Be sure to enter the correct path in this next line as well.
Set dbs = wrkAdmin.OpenDatabase("C:\Northwind.mdb", False)
Set ctrReports = dbs.Containers!Reports
Set docReport = ctrReports.Documents(strName)
' Assign Read permissions for to this report back to the Users group.
docReport.UserName = "Users"
docReport.Permissions = dbSecReadSec
' Close the session.
wrkAdmin.Close
End Sub
Dim PrtMipString As str_PRTMIP
Dim PM As type_PRTMIP
Dim rpt As Report
Dim strName As String
DoCmd.Echo False
strName = "Summary of Sales by Year"
DoCmd.OpenReport strName, acDesign
Set rpt = Reports(strName)
PrtMipString.strRGB = rpt.PrtMip
LSet PM = PrtMipString
PM.lngLeftMargin = 1 * 1440
PM.lngTopMargin = 1 * 1440
PM.lngRightMargin = 1 * 1440
PM.lngBotMargin = 1 * 1440
LSet PrtMipString = PM
rpt.PrtMip = PrtMipString.strRGB
DoCmd.Close acReport, strName, acSaveYes
DoCmd.OpenReport strName, acViewPreview
DoCmd.Echo True
Keywords: KB209867, kbprogramming, kbprb