Changing User Password

  • Thread starter Thread starter bigturnip
  • Start date Start date
B

bigturnip

I am banging my head against a brick wall here, probably a simpl
answer, I have the following code and know that it works except I don'
know how to set UsrPwd to the current user. I can use .createuser an
the rest of the code then works, but I don't want to create a new use
and the CurrentUser method gives a type mismatch.

I am using Access 2002 on Windows XP and the DAO 3.6 object library.
Any help would be appreciated.

Sub ChangePassword()

Dim wrkspc As Workspace
Dim UsrPwd As User
Dim strPasswordOld As String
Dim strPassword As String
Dim strPasswordConfirm As String

' Get default workspace.
Set wrkspc = DBEngine.Workspaces(0)
Set UsrPwd =
With wrkspc

strPasswordOld = InputBox("Enter old password")
strPassword = InputBox("Enter new password")
strPasswordConfirm = InputBox("Confirm new password")

If LCase(strPassword) <> LCase(strPasswordConfirm) Then
MsgBox "New Password did not match"
Exit Sub
End If

Select Case Len(strPassword)
Case 1 To 14
UsrPwd.newpassword strPasswordOld, LCase(strPassword)
MsgBox "Password changed!"
Case Is > 14
MsgBox "Password too long!"
Case 0
End Select


End With

End Sub
 
I use the follwing code to change the users password:

Function ChangePassword(ByVal strUser As String, _
ByVal strPwd As String) As Integer

Dim ws As Workspace
Dim usr As user

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUser)
usr.NewPassword "", strPwd

End Function

Note that you don't need the old password if you have admin privileges. If
you don't have admin privileges, then I *think* you have to provide the old
password.

Anyway, give the above a try
 
Back
Top