|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
users set their own passwordtheir own password on a newly secured database. I have many users set up with no password and would like to give them the ability to change it themselves but when I test the form I get an "Error 94 Invalid use of Null" message. Here is the code on the form in the On_Click event of a button: Private Sub cmdChangePassword_Click() On Error Resume Next If Me!txtNewPassword = Me!txtConfirmNewPassword Then ChangeUserPassword DBEngine(0).UserName, _ Me!txtCurrentPassword, Me!txtNewPassword If (Err <> 0) Then MsgBox "Error " & Err.Number & vbCrLf & _ Err.Description, vbOKOnly + vbExclamation, _ "Could not change password" End If Else MsgBox "The new passwords do not match." End If End Sub And here is the code in the Module: 'Change a user's password Public Sub ChangeUserPassword(strUser As String, _ strOldPassword As String, strNewPassword As String) Dim wrk As DAO.Workspace Dim usr As DAO.User Set wrk = DBEngine(0) Set usr = wrk.Users(strUser) 'Change the password usr.NewPassword strOldPassword, strNewPassword Set usr = Nothing Set wrk = Nothing End Sub I read threads about SetPassword but didn't see any supporting code samples. Could someone please tell me where I am going wrong? Thank you so much. have you stepped through the code to see exactly what line is triggering the
error? comment out the On Error Resume Next line, first. hth Show quoteHide quote "AccessIM" <Acces***@discussions.microsoft.com> wrote in message news:7220A756-2682-4DC8-B438-E54689B99F3C@microsoft.com... > I borrowed the following code for creating a form that the user's can set > their own password on a newly secured database. I have many users set up > with no password and would like to give them the ability to change it > themselves but when I test the form I get an "Error 94 Invalid use of Null" > message. > > Here is the code on the form in the On_Click event of a button: > > Private Sub cmdChangePassword_Click() > On Error Resume Next > > If Me!txtNewPassword = Me!txtConfirmNewPassword Then > ChangeUserPassword DBEngine(0).UserName, _ > Me!txtCurrentPassword, Me!txtNewPassword > > If (Err <> 0) Then > MsgBox "Error " & Err.Number & vbCrLf & _ > Err.Description, vbOKOnly + vbExclamation, _ > "Could not change password" > End If > Else > MsgBox "The new passwords do not match." > End If > > End Sub > > And here is the code in the Module: > > 'Change a user's password > Public Sub ChangeUserPassword(strUser As String, _ > strOldPassword As String, strNewPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > Set usr = wrk.Users(strUser) > > 'Change the password > usr.NewPassword strOldPassword, strNewPassword > > Set usr = Nothing > Set wrk = Nothing > End Sub > > I read threads about SetPassword but didn't see any supporting code samples. > Could someone please tell me where I am going wrong? Thank you so much. Hi Tina-
I correct the On Error line and found the code is stopping at the following line: ChangeUserPassword DBEngine(0).UserName, _ Me!txtCurrentPassword, Me!txtNewPassword I have been reading up on this error but have not found a solution. I think it is safe to assume the error is appearing because, at this point, all passwords are blank since i just set the users up. If I set a password for a user and use this form and code, it changes the password and everything works great. I just need to know how to change the code to accept the initial null value in the txtCurrentPassword field. Any suggestions? Show quoteHide quote "tina" wrote: > have you stepped through the code to see exactly what line is triggering the > error? comment out the On Error Resume Next line, first. > > hth > > > "AccessIM" <Acces***@discussions.microsoft.com> wrote in message > news:7220A756-2682-4DC8-B438-E54689B99F3C@microsoft.com... > > I borrowed the following code for creating a form that the user's can set > > their own password on a newly secured database. I have many users set up > > with no password and would like to give them the ability to change it > > themselves but when I test the form I get an "Error 94 Invalid use of > Null" > > message. > > > > Here is the code on the form in the On_Click event of a button: > > > > Private Sub cmdChangePassword_Click() > > On Error Resume Next > > > > If Me!txtNewPassword = Me!txtConfirmNewPassword Then > > ChangeUserPassword DBEngine(0).UserName, _ > > Me!txtCurrentPassword, Me!txtNewPassword > > > > If (Err <> 0) Then > > MsgBox "Error " & Err.Number & vbCrLf & _ > > Err.Description, vbOKOnly + vbExclamation, _ > > "Could not change password" > > End If > > Else > > MsgBox "The new passwords do not match." > > End If > > > > End Sub > > > > And here is the code in the Module: > > > > 'Change a user's password > > Public Sub ChangeUserPassword(strUser As String, _ > > strOldPassword As String, strNewPassword As String) > > Dim wrk As DAO.Workspace > > Dim usr As DAO.User > > > > Set wrk = DBEngine(0) > > Set usr = wrk.Users(strUser) > > > > 'Change the password > > usr.NewPassword strOldPassword, strNewPassword > > > > Set usr = Nothing > > Set wrk = Nothing > > End Sub > > > > I read threads about SetPassword but didn't see any supporting code > samples. > > Could someone please tell me where I am going wrong? Thank you so much. > > > as Chris said, the problem is probably the Null value in txtCurrentPassword.
try ChangeUserPassword DBEngine(0).UserName, _ Nz(Me!txtCurrentPassword, ""), Me!txtNewPassword hth Show quoteHide quote "AccessIM" <Acces***@discussions.microsoft.com> wrote in message news:3168C1A7-F014-4AA7-B7F0-82FA1C9A8F31@microsoft.com... > Hi Tina- > > I correct the On Error line and found the code is stopping at the following > line: > > ChangeUserPassword DBEngine(0).UserName, _ > Me!txtCurrentPassword, Me!txtNewPassword > > I have been reading up on this error but have not found a solution. I think > it is safe to assume the error is appearing because, at this point, all > passwords are blank since i just set the users up. If I set a password for a > user and use this form and code, it changes the password and everything works > great. I just need to know how to change the code to accept the initial null > value in the txtCurrentPassword field. > > Any suggestions? > > > > "tina" wrote: > > > have you stepped through the code to see exactly what line is triggering the > > error? comment out the On Error Resume Next line, first. > > > > hth > > > > > > "AccessIM" <Acces***@discussions.microsoft.com> wrote in message > > news:7220A756-2682-4DC8-B438-E54689B99F3C@microsoft.com... > > > I borrowed the following code for creating a form that the user's can set > > > their own password on a newly secured database. I have many users set up > > > with no password and would like to give them the ability to change it > > > themselves but when I test the form I get an "Error 94 Invalid use of > > Null" > > > message. > > > > > > Here is the code on the form in the On_Click event of a button: > > > > > > Private Sub cmdChangePassword_Click() > > > On Error Resume Next > > > > > > If Me!txtNewPassword = Me!txtConfirmNewPassword Then > > > ChangeUserPassword DBEngine(0).UserName, _ > > > Me!txtCurrentPassword, Me!txtNewPassword > > > > > > If (Err <> 0) Then > > > MsgBox "Error " & Err.Number & vbCrLf & _ > > > Err.Description, vbOKOnly + vbExclamation, _ > > > "Could not change password" > > > End If > > > Else > > > MsgBox "The new passwords do not match." > > > End If > > > > > > End Sub > > > > > > And here is the code in the Module: > > > > > > 'Change a user's password > > > Public Sub ChangeUserPassword(strUser As String, _ > > > strOldPassword As String, strNewPassword As String) > > > Dim wrk As DAO.Workspace > > > Dim usr As DAO.User > > > > > > Set wrk = DBEngine(0) > > > Set usr = wrk.Users(strUser) > > > > > > 'Change the password > > > usr.NewPassword strOldPassword, strNewPassword > > > > > > Set usr = Nothing > > > Set wrk = Nothing > > > End Sub > > > > > > I read threads about SetPassword but didn't see any supporting code > > samples. > > > Could someone please tell me where I am going wrong? Thank you so much. > > > > > > You're passing a null value as a parameter to a data type (string) that can't
accept nulls. Use the nz function to assign a zero length string to the value passed to strOldPassword when the value is null. Chris AccessIM wrote: Show quoteHide quote >when I test the form I get an "Error 94 Invalid use of Null" >message. > >Here is the code on the form in the On_Click event of a button: > >Private Sub cmdChangePassword_Click() > On Error Resume Next > > If Me!txtNewPassword = Me!txtConfirmNewPassword Then > ChangeUserPassword DBEngine(0).UserName, _ > Me!txtCurrentPassword, Me!txtNewPassword > > If (Err <> 0) Then > MsgBox "Error " & Err.Number & vbCrLf & _ > Err.Description, vbOKOnly + vbExclamation, _ > "Could not change password" > End If > Else > MsgBox "The new passwords do not match." > End If > >End Sub > >And here is the code in the Module: > >'Change a user's password >Public Sub ChangeUserPassword(strUser As String, _ > strOldPassword As String, strNewPassword As String) > Dim wrk As DAO.Workspace > Dim usr As DAO.User > > Set wrk = DBEngine(0) > Set usr = wrk.Users(strUser) > > 'Change the password > usr.NewPassword strOldPassword, strNewPassword > > Set usr = Nothing > Set wrk = Nothing >End Sub -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-security/200906/1
Understandable documentation regarding Access DBA security
Unable to compact/repair because I have it opened Access Networking & Security Issue. Read-Only Database! Need Help With Security After migrating .mdb to v.2007 & rename mdw file, v.2007 lets me i Upgrade a password protected database Allow a Disk as a Trusted Location or disable it entirely Need help with creating MDE file Trace a user in network version of database |
|||||||||||||||||||||||