ACC: How to Prevent Users from Creating New Databases

ID: Q123483


The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97


SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes how to use the security constant dbSecDBCreate (or DB_SEC_DBCREATE in version 2.0) to prevent database users from creating new databases. This constant can be set and removed only with Visual Basic for Applications code.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access version 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.


MORE INFORMATION

When you negate the security constant dbSecDBCreate (or DB_SEC_DBCREATE in version 2.0) for a user, you remove that user's permission to create new databases. The following example demonstrates how to use the dbSecDBCreate constant to remove the permission to create new databases from all users in the Users group:

  1. Quit Microsoft Access if it is running. Copy the System.mdw file (or SYSTEM.MDA file in version 2.0), usually in the Access folder, to a file with another name. For example, copy the file to a file named System.bak.


  2. Start Microsoft Access and open the sample database Northwind.mdb (or NWIND.MDB in version 2.0).


  3. Create a new module and type the following line in the Declarations section if it is not already there:
    Option Explicit


  4. Type the following code in the module.

    In Microsoft Access 7.0 and 97:
    
          Function Remove_DBCreate()
            Dim d As Database, c As Container, SystemDB As String
            SystemDB = "c:\access\system.mda" ' Use path for your system.
            Set d = DBEngine(0).OpenDatabase(SystemDB)
            Set c = d.Containers!Databases
            c.Username = "Users"
            c.Permissions = c.Permissions And Not dbSecDBCreate
          End Function 
    In Microsoft Access 2.0:
    
          Function Remove_DBCreate()
            Dim d As Database, c As Container, SystemDB As String
            SystemDB = "c:\access\system.mda" ' Use path for your system.
            Set d = DBEngine(0).OpenDatabase(SystemDB)
            Set c = d.Containers!Databases
            c.Username = "Users"
            c.Permissions = c.Permissions And Not DB_SEC_DBCREATE
          End Function 


  5. On the View menu, click Debug Window (or Immediate Window in version 2.0).


  6. In the Debug window, type the following line, and then press ENTER:
    ?Remove_DBCreate()


  7. Quit Microsoft Access, and then restart it. Log in as a member of the Users group.


  8. On the File menu, click New Database. In the File Name box, type c:\db1.mdb, and then click OK. Note that you receive the following message:
    No permissions on 'C:\DB1.MDB'


Note that if a member of the Users group has permission to create new databases by also belonging to another group (such as the Admins group), that user will still be able to create new databases. Microsoft Access uses the most liberal permissions of the groups that a user belongs to.


REFERENCES

For more information about permissions, search the Help Index for "Permissions property," or ask the Microsoft Access 97 Office Assistant.

Additional query words: rights

Keywords : kbusage ScrtPerm
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 12, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.