Microsoft KB Archive/210154

= HOW TO: Change the Owner of a New Table in Access 2000 =

Article ID: 210154

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210154



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).

IN THIS TASK
SUMMARY
 * Method 1: Using a Macro
 * Method 2: Using Visual Basic for Applications

REFERENCES



SUMMARY
This article describes a method that you can use to transfer the ownership of a newly created table to a specific owner. For example, if the functionality within a secured database enables the current user to import a table, that user will be the owner of the table and will have full permissions on that table.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

If your secured database application enables users to import a table, those users will be the owners of the table and will have full permissions on that table. The function in this article demonstrates how you can programmatically create a secured session as a user different from the current user and transfer ownership of an imported object from the current user to another user.

Call the following function within a macro, a function, or a Sub procedure that imports the table that you want to secure. Call the function immediately after importing the table to ensure that permissions have been set.

Function ChangeOwner(NewTable As String, NewOwner As String, PWord As _ String)

Dim NewWS As WorkSpace Dim db As Database Dim cnt As Container Dim doc As Document

Set db = CurrentDB

'Create a new session and append it to the Workspaces collection. Set NewWS = dbengine.CreateWorkspace("NewWS", NewOwner, PWord)

'Assign variables for the table's Container and Document objects. Set cnt = db.Containers("Tables") Set doc = cnt.Documents(NewTable)

'Establish new owner of the imported table. doc.Owner = NewOwner

'Cleanup. NewWS.Close db.Close

'Pass success status back to caller. ChangeOwner = True

End Function To use the ChangeOwner function, use either of the following methods. Each assumes that the table has just been imported, that the table is named MyTable, and that a valid user named MyNewOwner with a password of MyNewOwnerPass exists.

back to the top

Method 1: Using a Macro
  Action: RunCode Function Name: ChangeOwner("MyTable","MyNewOwner", "MyNewOwnerPass")

back to the top

Method 2: Using Visual Basic for Applications
Dim IsOwnerChanged as Integer IsOwnerChanged = ChangeOwner("MyTable", "MyNewOwner", "MyNewOwnerPass")

back to the top

