Private Sub OK_Click()
On Error GoTo Err_OK_Click
Dim strUser As String
Dim strOldPW1 As String
Dim strNewPW1 As String
Dim strNewPW2 As String
Dim strMsg As String
Dim strTitle As String
Dim intType As Integer
Dim wrk As Object
Dim usrLocal As Object
strUser = CurrentUser()
If strUser = "Admin" Then
strMsg = "Password for Admin can't be changed. Please contact system administrator."
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
End If
If IsNull(Forms![yourform]![youroldpasswordfield]) Then
' strMsg = "No Old Password entered"
' strTitle = "Password"
' intType = 16
' MsgBox strMsg, intType, strTitle
' Exit Sub
strOldPW1 = ""
Else
strOldPW1 = Forms![yourfrom]![youroldpasswordfield]
End If
If IsNull(Forms![yourfrom]![yournewpasswordfield]) Then
strMsg = "No New Password entered"
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
End If
If IsNull(Forms![yourform]![yournewpasswordconfirmfield]) Then
strMsg = "No verify entered"
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
End If
strNewPW1 = Forms![yourfrom]![yournewpasswordfield]
strNewPW2 = Forms![yourfrom]![yournewpasswordfieldconfirm]
Set wrk = DBEngine.Workspaces(0)
Set usrLocal = wrk.Users(strUser)
'* Check if New password and verify are the same
If strNewPW1 = strNewPW2 Then
'* Check Length of new password
If Len(strNewPW1) <= 14 Then
usrLocal.NewPassword strOldPW1, strNewPW1
Else
strMsg = "Password can have a length of maximum 14 characters."
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
End If
Else
strMsg = "Please verify the new password by entering it in the"
strMsg = strMsg + Chr$(13) & Chr$(10)
strMsg = strMsg + "verify box."
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
End If
DoCmd.Close
Exit_OK_Click:
Exit Sub
Err_OK_Click:
If Err = 3033 Then
strMsg = "Old Password not correct for this user profile."
strTitle = "Password"
intType = 16
MsgBox strMsg, intType, strTitle
Exit Sub
Else
MsgBox Error$
Resume Exit_OK_Click
End If
End Sub