萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> access教程 >> access基礎教程 >> 修改工作組用戶密碼

修改工作組用戶密碼

下面是修改工作組用戶密碼的函數,調用時如果用於密碼為空,請使用"",不要使用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

copyright © 萬盛學電腦網 all rights reserved