Granting Read Permission to a User for a Table

The following example grants a user or group permissions on a single table or query in a database. It sets the UserName property of the document to the user or group for whom you want to change permissions. Then the code sets the permissions by modifying the Permissions property of the Document object. Note that instead of explicitly setting the Permissions property to dbSecRetrieveData, the Or operator is used to add the permission to any existing permissions. This ensures that this code does not remove other permissions that the user has already been assigned. In this example, strDbPath is the path to the database, strUser is the name of a user or group, and strDocument is the name of the Document object.

Sub GrantReadPerms(strDbPath As String, strUser As String, strDocument As String)
	Dim dbs As Database
	Dim doc As Document
	
	Set dbs = OpenDatabase(strDbPath)
	Set doc = dbs.Containers("Tables").Documents(strDocument)
	With doc
		' Specify user or group name.
		.UserName = strUser
		' Add read permissions to existing permissions.
		.Permissions = doc.Permissions Or dbSecRetrieveData
	End With
End Sub