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
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.
back to the top