Home All Groups Group Topic Archive Search About

users set their own password

Author
1 Jun 2009 5:29 PM
AccessIM
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.

Author
2 Jun 2009 12:38 AM
tina
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.
Are all your drivers up to date? click for free checkup

Author
3 Jun 2009 8:34 PM
AccessIM
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.
>
>
>
Author
4 Jun 2009 12:52 AM
tina
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.
> >
> >
> >
Author
3 Jun 2009 9:20 PM
Chris O'C via AccessMonster.com
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


Bookmark and Share