Article ID: 200665
Article Last Modified on 10/11/2006
Public Sub ChangeResetPassword(StrAction As String, StrUsername As _
String, StrAdminLogon As String, StrAdminPass As String, Optional _
StrNewPassword As Variant)
Dim ws As Workspace
On Error GoTo ChangeResetPassword:
' Create a new Administrative Workspace. If The StrAction passed to the
' function is "Change" then change the Password of the User named in
' StrUsername to the password saved in StrNewPassword.
' If the StrAction passed is "Reset", Then reset the password of
' the User mentioned in StrUsername. If neither "Change" or "Reset"
' is passed to the function in the StrAction argument, inform the
' user of an error and exit the procedure.
Set ws = DBEngine.CreateWorkspace("AdminWorkspace", StrAdminLogon, _
StrAdminPass)
If StrAction = "change" Then
If Not IsNull(StrNewPassword) Then
ws.Users(StrUsername).NewPassword "", StrNewPassword
MsgBox "Password Change Successful", vbOKOnly
Else
MsgBox "When Attempting to Change A User's Password, You " & _
"Must Include a New Password", vbOKOnly
End If
ElseIf StrAction = "reset" Then
'When the current user is in the admins group and reseting
'his/her own password, the current password must be supplied.
'In all other cases, the current user password is not needed
'for a reset.
If StrUsername = ws.UserName And StrAdminLogon = ws.UserName Then
ws.Users(StrUsername).NewPassword StrAdminPass, ""
MsgBox "Password Successfully Reset", vbOKOnly
Else
ws.Users(StrUsername).NewPassword "", ""
MsgBox "Password Successfully Reset", vbOKOnly
End If
Else
MsgBox "You must Select a StrAction of either '" & "Change'" & _
"' or '" & "Reset'.", vbOKOnly
End If
ws.Close
Set ws = Nothing
Exit Sub
ChangeResetPassword:
MsgBox Err.Description
End Sub
Public Sub ChangeUserPassword(StrUsername As String, StrOldPassword _
As String, StrNewPassword As String)
On Error GoTo ChangeUserPassword_Err:
DBEngine(0).Users(StrUsername).NewPassword StrOldPassword, _
StrNewPassword
MsgBox "Password Change Successful", vbInformation
Exit Sub
ChangeUserPassword_Err:
MsgBox Err.Description
End Sub
- Change their own password.The form allows administrators to:
- Reset a user's password. - Change a user's password.To create the form, follow these steps:
Text Box:
-----------------
Name: txtUserName
Label:
--------------------
Name: lblUserName
Caption: UserName
Text Box:
-----------------------
Name: txtOldPassword
Input Mask: Password
Label:
------------------------
Name: lblOldPassword
Caption: Old Password
Text Box:
------------------------
Name: txtNewPassword
Input Mask: Password
Label:
------------------------
Name: lblNewPassword
Caption: New Password
Text Box:
-----------------------
Name: txtVerifyPassword
Input Mask: Password
Label:
---------------------------
Name: lblVerify Password
Caption: Verify Password
Text Box:
-----------------------
Name: txtAdminUsername
Input Mask: Password
Label:
-----------------------------------
Name: lblAdminUsername
Caption: Administrative UserName
Text Box:
-----------------------
Name: txtAdminPassword
Input Mask: Password
Label:
-----------------------------------
Name: lblAdminPassword
Caption: Administrative Password
Command Button:
-----------------------------------------------
Name: CmdChange
Caption: Change Password(Non-Administrative)
Height: 720
Width: 1440
Command Button:
-------------------------------------------
Name: CmdChangeAdmin
Caption: Change Password(Administrative)
Height: 720
Width: 1440
Command Button:
------------------------------------------
Name: CmdReset
Caption: Reset Password(Administrative)
Height: 720
Width: 1440
Option Explicit
Private Sub CmdChange_Click()
On Error GoTo CmdChange_err
' Make sure the password typed in the New Password text box
' matches what has been typed in the Verify Password text box.
If Me!txtNewPassword <> Me!txtVerifyPassword Then
MsgBox "The New and Verified Passwords Do Not Match. " & _
"Please Re-enter", vbCritical
Me!txtNewPassword = ""
Me!txtNewVerifyPassword = ""
Me!txtNewPassword.SetFocus
Else
' Check to make sure the Old Password has been filled in and
' if it has, change the password.
If IsNull(Me!txtOldPassword) Then
MsgBox "Leaving the Old Password textbox empty will cause " & _
"an error unless you currently have no password", vbOKOnly
Call ChangeUserPassword(CurrentUser(), "", Me!txtNewPassword)
Else
Call ChangeUserPassword(CurrentUser(), Me!txtOldPassword, _
Me!txtNewPassword)
End If
End If
Exit Sub
CmdChange_err:
MsgBox Err.Description
End Sub
Private Sub cmdChangeAdmin_Click()
On Error GoTo CmdChangeAdmin_err
' Test to make sure appropriate text boxes are filled in because this
' is an administrative function.
If Not IsNull(Me!txtAdminPassword) And Not _
isNull(Me!txtAdminUsername) And Not IsNull(Me!txtUserName) Then
If Me!txtNewPassword <> Me!txtVerifyPassword Then
MsgBox "The New and Verified Passwords Do Not Match. Please" & _
" Re-enter", vbCritical
Me!txtNewPassword = ""
Me!txtNewVerifyPassword = ""
Me!txtNewPassword.SetFocus
Else
Call ChangeResetPassword("Change",Me!txtUserName, _
me!txtAdminUsername, me!txtAdminPassword, Me!txtNewPassword)
End If
Else
MsgBox "The textboxes for UserName, New Password, Verified " & _
"Password, Admin UserName and Admin Password must be complete " & _
"for this function to operate correctly.", vbOKOnly
End If
Exit Sub
CmdChangeAdmin_err:
MsgBox Err.Description
End Sub
Private Sub cmdReset_Click()
On Error GoTo CmdReset_err
' Test to make sure appropriate textboxes are filled in because this is
' an administrative function.
If Not IsNull(Me!txtAdminPassword) And Not _
IsNull(Me!txtAdminUsername) And Not IsNull(Me!txtUserName) Then
Call ChangeResetPassword("Reset", Me!txtUserName, _
Me!txtAdminUsername, Me!txtAdminPassword)
Else
MsgBox "The textboxes for UserName, New Password, Verified " & _
"Password, Admin UserName and Admin Password must be complete " & _
"for this function to operate correctly.", VBOKOnly
End If
Exit Sub
CmdReset_err:
MsgBox Err.Description
End Sub
Additional query words: pass word forget lost forgot
Keywords: kbhowto kbprogramming KB200665