Microsoft KB Archive/180281: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 135: | Line 135: | ||
Dim strName As String | Dim strName As String | ||
strName = | strName = "Summary of Sales by Year" | ||
' Create a new session and assign it to the database administrator. | ' Create a new session and assign it to the database administrator. | ||
Set wrkAdmin = DBEngine.CreateWorkspace( | Set wrkAdmin = DBEngine.CreateWorkspace("AdminWorkspace", "Admin", _ | ||
"Admin", dbUseJet) | |||
' Be sure to change the path in this next line to match your path to | ' Be sure to change the path in this next line to match your path to | ||
' Northwind.mdb. | ' Northwind.mdb. | ||
Set dbs = wrkAdmin.OpenDatabase( | Set dbs = wrkAdmin.OpenDatabase("C:\Northwind.mdb", False) | ||
Set ctrReports = dbs.Containers!Reports | Set ctrReports = dbs.Containers!Reports | ||
Set docReport = ctrReports.Documents(strName) | Set docReport = ctrReports.Documents(strName) | ||
' Give the Users group full permissions to this report. | ' Give the Users group full permissions to this report. | ||
docReport.UserName = | docReport.UserName = "Users" | ||
docReport.Permissions = dbSecFullAccess | docReport.Permissions = dbSecFullAccess | ||
Line 164: | Line 164: | ||
' The new margin settings to be used are half inch. | ' The new margin settings to be used are half inch. | ||
' Note: The Summary of Sales by Year report has 1 | ' Note: The Summary of Sales by Year report has 1" margins by | ||
' default. | ' default. | ||
PM.lngLeftMargin = 0.5 * 1440 | PM.lngLeftMargin = 0.5 * 1440 | ||
Line 184: | Line 184: | ||
' Re-create a new session, assigning it to the database | ' Re-create a new session, assigning it to the database | ||
' administrator. | ' administrator. | ||
Set wrkAdmin = DBEngine.CreateWorkspace( | Set wrkAdmin = DBEngine.CreateWorkspace("AdminWorkspace", "Admin", _ | ||
"Admin", dbUseJet) | |||
' Be sure to enter the correct path in this next line as well. | ' Be sure to enter the correct path in this next line as well. | ||
Set dbs = wrkAdmin.OpenDatabase( | Set dbs = wrkAdmin.OpenDatabase("C:\Northwind.mdb", False) | ||
Set ctrReports = dbs.Containers!Reports | Set ctrReports = dbs.Containers!Reports | ||
Set docReport = ctrReports.Documents(strName) | Set docReport = ctrReports.Documents(strName) | ||
' Assign Read permissions for to this report back to the Users group. | ' Assign Read permissions for to this report back to the Users group. | ||
docReport.UserName = | docReport.UserName = "Users" | ||
docReport.Permissions = dbSecReadSec | docReport.Permissions = dbSecReadSec | ||
Line 212: | Line 212: | ||
- Read Data and Read Design on the Summary of Sale by Year query<br /> | - Read Data and Read Design on the Summary of Sale by Year query<br /> | ||
- Open/Run on the Form1 form<br /> | - Open/Run on the Form1 form<br /> | ||
- Open/Run, Read Design and Modify Design on the | - Open/Run, Read Design and Modify Design on the "Summary of Sales by Year" report<br /> | ||
</p> | </p> | ||
</div></li> | </div></li> | ||
<li>Assign the password | <li>Assign the password "Admin" (without the quotation marks) to the Admin user.</li> | ||
<li>Close and restart Microsoft Access.</li> | <li>Close and restart Microsoft Access.</li> | ||
<li>Type | <li>Type "Guest" (without the quotation marks) as the logon name, and press ENTER.</li> | ||
<li>Open the Form1 form in Form view, and click the command button. Note that the | <li>Open the Form1 form in Form view, and click the command button. Note that the "Summary of Sales by Year" report displays in Print Preview with half inch margins.</li></ol> | ||
NOTE: Because we have assigned only Open/Run permissions to the Form1 form, it is impossible for the user to open the form in Design view in order to discover what the Admin's password is. However, keep in mind that a properly secured database would never use the default Admin account as the administrator of a database. | NOTE: Because we have assigned only Open/Run permissions to the Form1 form, it is impossible for the user to open the form in Design view in order to discover what the Admin's password is. However, keep in mind that a properly secured database would never use the default Admin account as the administrator of a database. | ||
Line 243: | Line 243: | ||
<ol> | <ol> | ||
<li>Repeat steps 1 through 7 in the | <li>Repeat steps 1 through 7 in the "Resolution" section of this article.</li> | ||
<li><p>Set the command button's OnClick property to the following event procedure:</p> | <li><p>Set the command button's OnClick property to the following event procedure:</p> | ||
<pre class="codesample"> Dim PrtMipString As str_PRTMIP | <pre class="codesample"> Dim PrtMipString As str_PRTMIP | ||
Line 251: | Line 251: | ||
DoCmd.Echo False | DoCmd.Echo False | ||
strName = | strName = "Summary of Sales by Year" | ||
DoCmd.OpenReport strName, acDesign | DoCmd.OpenReport strName, acDesign | ||
Line 296: | Line 296: | ||
== REFERENCES == | == REFERENCES == | ||
For more information about the PrtDevMode or PrtMip property, search the Help Index for | For more information about the PrtDevMode or PrtMip property, search the Help Index for "PrtDevMode Property" or "PrtMip Property", or ask the Microsoft Access 97 Office Assistant.<br /> | ||
<br /> | <br /> | ||
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: | For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: |
Latest revision as of 11:10, 21 July 2020
Article ID: 180281
Article Last Modified on 1/22/2007
APPLIES TO
- Microsoft Access 97 Standard Edition
This article was previously published under Q180281
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
In an MDE file, you cannot use the PrtDevMode or PrtMip property to change printer information for forms and reports. If you try to modify printer information by programmatically using the PrtDevMode or PrtMip property, you may receive the following error message:
CAUSE
To modify printer information using the PrtDevMode or PrtMip property, the form or report must first be opened in Design view. However, forms, reports, and modules cannot be opened in Design mode within an MDE file.
RESOLUTION
Instead of creating MDE files, create a Microsoft Access database and add Microsoft Access Security to the database. Adding security to your Microsoft Access database (MDB) will prevent users from viewing the design of your forms, reports, modules, and so on.
IMPORTANT: This resolution assumes that you understand the Microsoft Access Security model.
If you use a Microsoft Access database that has been secured, you can use the CreateWorkspace method to create a session for the Administrator of the database while programmatically modifying printer information using PrtDevMode or PrtMip property.
For more information on Microsoft Access Security, see the following documentation:
148555 ACC95: MS Access 95 Security White Paper Available in Download Center
132143 ACC: Overview of How to Secure a Microsoft Access Database
The following example uses the default Admin user as the Administrator of the Northwind database, and allows user Guest to open a report, change its marginal settings, and then preview the report.
CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
- Open the sample database Northwind.mdb.
Create a module and type the following lines in the Declarations section:
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
- Save and close the module.
- Open a new form not based on any table or query in Design view.
- Add a command button to the form.
Set the command button's OnClick property to the following event procedure:
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
- Save the form as Form1 and close it.
- Remove all permissions for the Users group for all objects.
- Create a new user called Guest.
- Assign the following permissions to the Guest user:
- Open/Run on the Current Database
- Read Data and Read Design on the Order Details table
- Read Data and Read Design on the Orders table
- Read Data and Read Design on the Order Subtotals query
- Read Data and Read Design on the Summary of Sale by Year query
- Open/Run on the Form1 form
- Open/Run, Read Design and Modify Design on the "Summary of Sales by Year" report
- Assign the password "Admin" (without the quotation marks) to the Admin user.
- Close and restart Microsoft Access.
- Type "Guest" (without the quotation marks) as the logon name, and press ENTER.
- Open the Form1 form in Form view, and click the command button. Note that the "Summary of Sales by Year" report displays in Print Preview with half inch margins.
NOTE: Because we have assigned only Open/Run permissions to the Form1 form, it is impossible for the user to open the form in Design view in order to discover what the Admin's password is. However, keep in mind that a properly secured database would never use the default Admin account as the administrator of a database.
STATUS
This behavior is by design.
MORE INFORMATION
Printer page setup properties such as PrtDevMode and PrtMip enable you to programmatically manipulate the printer information specified for Microsoft Access forms and reports. The PrtDevMode and PrtMip properties enable you to read a form or report's current printer settings as well as update the printer settings.
Unlike run-time applications, which allow the PrtDevMode and PrtMip properties to open forms and reports in Design view, MDE file formats do not allow forms and reports to be opened in Design view.
Steps to Reproduce Behavior
- Repeat steps 1 through 7 in the "Resolution" section of this article.
Set the command button's OnClick property to the following event procedure:
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
- Save the form as Form1 and open it in Form view. Note that you can preview the report without any errors.
- Close the report and the form.
- On the Tools menu, click Database Utilities, and then click Make MDE File, and save the Northwind database in an MDE format.
- Open Northwind.mde and double-click the Form1 form to open it.
- Click the command button. Note that you receive the following error message:
REFERENCES
For more information about the PrtDevMode or PrtMip property, search the Help Index for "PrtDevMode Property" or "PrtMip Property", or ask the Microsoft Access 97 Office Assistant.
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: kbcode kbmacro vba
Keywords: kbprb kbprogramming KB180281