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

Article translations Article translations
Article ID: 210154 - View products that this article applies to.
This article was previously published under Q210154
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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.

Method 1: Using a Macro

   Action: RunCode
   Function Name: ChangeOwner("MyTable","MyNewOwner", "MyNewOwnerPass")
				

Method 2: Using Visual Basic for Applications

Dim IsOwnerChanged as Integer
IsOwnerChanged = ChangeOwner("MyTable", "MyNewOwner", "MyNewOwnerPass")
				





References

For more information about database security and object ownership, click Microsoft Access Help on the Help menu, type secure a microsoft access database in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about running a Function procedure from a macro, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type runcode action in the Office Assistant or the Answer Wizard, and then click Search to view the topic.









Properties

Article ID: 210154 - Last Review: October 26, 2013 - Revision: 4.0
Applies to
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbhowtomaster kbprogramming kbusage KB210154

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com