UserName Property Example

This example uses the UserName property to change a particular user's permissions on an object and to verify that user's ability to append new data to the same object.

Sub UserNameX()

    ' Ensure that the Microsoft Jet workgroup information 
    ' file is available.
    DBEngine.SystemDB = "system.mdw"

    Dim dbsNorthwind As Database
    Dim docTemp As Document

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")

    Set docTemp = _
        dbsNorthwind.Containers("Tables").Documents(0)

    ' Change the permissions of NewUser on the first Document 
    ' object in the Tables container.
    With docTemp
        .UserName = "NewUser"
        .Permissions = dbSecRetrieveData
        If (.Permissions And dbSecInsertData) = _
                dbSecInsertData Then
            Debug.Print .UserName & " can insert data."
        Else
            Debug.Print .UserName & " can't insert data."
        End If
    End With

    dbsNorthwind.Close

End Sub