下面是修改工作组用户密码的函数,调用时如果用于密码为空,请使用"",不要使用null,两者不同。:)
Function CheckUserPasswordInGroup(UserName As String,_ oldPassword As String, newPassword As String) As Boolean On Error GoTo ChkErr Dim wk As DAO.Workspace, Ur As DAO.User, i As Integer, Found As Boolean CheckUserPasswordInGroup = False Found = False Set wk = DBEngine.CreateWorkspace("", "Admin", "") '//要特别注意上面一句,必须使用拥有数据库管理权限的用户名和密码打开工作区!
'//下面一段是查找用户名是否存在,如果存在,修改密码,不存在出错报告。 For i = 0 To wk.Users.Count - 1 If wk.Users(i).Name = UserName Then Set Ur = wk.Users(i) Found = True Ur.newPassword oldPassword, newPassword Exit For End If Next i
If Not Found Then MsgBox "'" & UserName & "' 不是一个有效的用户名!",_ VBExclamation, "艾赛思应用网" CheckUserPasswordInGroup = False Exit Function End If CheckUserPasswordInGroup = True Exit Function ChkErr: MsgBox "'" & UserName & "' 用户密码修改失败!",_ vbExclamation, "艾赛思应用网" CheckUserPasswordInGroup = False End Function |