NewPassword Method Example

This example asks the user for a new password for user Pat Smith. If the input is a string between 1 and 14 characters long, the example uses the NewPassword method to change the password. The user must be logged on as Pat Smith or as a member of the Admins group.

Sub NewPasswordX()

    Dim wrkDefault As Workspace
    Dim usrNew As User
    Dim grpNew As Group
    Dim grpMember As Group
    Dim strPassword As String

    ' Get default workspace.
    Set wrkDefault = DBEngine.Workspaces(0)

    With wrkDefault

        ' Create and append new user.
        Set usrNew = .CreateUser("Pat Smith", _
            "abc123DEF456", "Password1")
        .Users.Append usrNew

        ' Create and append new group.
        Set grpNew = .CreateGroup("Accounting", _
            "UVW987xyz654")
        .Groups.Append grpNew

        ' Make the new user a member of the new group.
        Set grpMember = usrNew.CreateGroup("Accounting")
        usrNew.Groups.Append grpMember

        ' Ask user for new password. If input is too long, ask 
        ' again.
        Do While True
            strPassword = InputBox("Enter new password:")
            Select Case Len(strPassword)
                Case 1 To 14
                    usrNew.NewPassword "Password1", strPassword
                    MsgBox "Password changed!"
                    Exit Do
                Case Is > 14
                    MsgBox "Password too long!"
                Case 0
                    Exit Do
            End Select
        Loop

        ' Delete new User and Group objects because this
        ' is only a demonstration.
        .Users.Delete "Pat Smith"
        .Groups.Delete "Accounting"

    End With

End Sub