Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Se aplica a: Access 2013, Office 2013
En este ejemplo, se muestran los métodos GetObjectOwner y SetObjectOwner. Este código supone la existencia del grupo Contabilidad (vea el ejemplo de métodos Groups and Users Append, ChangePassword (VB) para ver cómo agregar este grupo al sistema). El propietario de la tabla Categorías se establece en Contabilidad.
' BeginOwnersVB
Sub Main()
On Error GoTo OwnersXError
Dim tblLoop As New ADOX.Table
Dim cat As New ADOX.Catalog
Dim strOwner As String
' Open the Catalog.
cat.ActiveConnection = "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='c:\Program Files\" & _
"Microsoft Office\Office\Samples\Northwind.mdb';" & _
"jet oledb:system database=" & _
"'c:\Program Files\Microsoft Office\Office\system.mdw'"
' Print the original owner of Categories
strOwner = cat.GetObjectOwner("Categories", adPermObjTable)
Debug.Print "Owner of Categories: " & strOwner
' Set the owner of Categories to Accounting
cat.SetObjectOwner "Categories", adPermObjTable, "Accounting"
' List the owners of all tables and columns in the catalog.
For Each tblLoop In cat.Tables
Debug.Print "Table: " & tblLoop.Name
Debug.Print " Owner: " & _
cat.GetObjectOwner(tblLoop.Name, adPermObjTable)
Next tblLoop
' Restore the original owner of Categories
cat.SetObjectOwner "Categories", adPermObjTable, strOwner
'Clean up
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Exit Sub
OwnersXError:
Set cat = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndOwnersVB