Allowing users to change their password

jonman03

Registered User.
Local time
Today, 09:48
Joined
Nov 5, 2009
Messages
31
I have been working with the Users and Groups security permissions on my database, and I wanted to offer an option on my switchboard for the user to change their password if they wanted.

I was thinking a button that ran a macro to bring up the password change form...but I cant figure out how to point to this exact thing in the Macro.

I'm trying to get to here (in Access 2003): Tools --> Security --> User and Group Accounts... --> "Change Logon Password" tab.

Is there any way to point the cmd button directly to this screen?

Thank you!
 
you wont do that with a macro

given controls oldpassword and newpassword, this vba will do what you want

i actually request the oldpassword, and newpassword twice, and check that they arent blank, and that they match, and stuff like that

Code:
Private Sub OKButton_Click()
    Dim usr As User
    Dim wrk As Workspace
    
                Set wrk = DBEngine.Workspaces(0)
                Set usr = wrk.Users(currentUser)
                On Error GoTo Error_OK
                usr.NewPassword Nz(Me.OldPassword, ""), Me.NewPassword
                Set usr = Nothing
                Set wrk = Nothing
end sub
 
Dave,

I am getting an error with that code when I try to run it. It is highlighting ".OldPassword" and says "Compile Error: Method or data member not found"

Here is the code I entered:
Code:
Private Sub ChangePass_Click()
Dim usr As User
Dim wrk As Workspace

Set wrk = DBEngine.Workspaces(0)
Set usr = wrk.Users(CurrentUser)
On Error GoTo Error_OK
usr.NewPassword Nz (Me.OldPassword, ""), Me.NewPassword
Set usr = Nothing
Set wrk = Nothing

End Sub
... Just came to my mind, but do I need a textbox named "NewPassword" and "OldPassword" on the form that contains this button?

Edit: I did the above, created the 2 textboxes and got an error saying "Label not defined".

Thanks for all your help.
 
Last edited:
yes, you need those controls on the form

i think these are dao methods also, so you need dao marked in access references
 
I created a simple form with 2 textboxes and the command button with this code.

One textbox named "OldPassword" and another named "NewPassword".

I have Microsoft DAO 3.6 Object Library selected in VB.
 
When testing with the above I'm getting the debugger highlighting the On Error... line of the code and saying "Compile Error: Label not defined"
 
When testing with the above I'm getting the debugger highlighting the On Error... line of the code and saying "Compile Error: Label not defined"
That's because in the code you posted
Code:
Private Sub ChangePass_Click()
Dim usr As User
Dim wrk As Workspace
 
Set wrk = DBEngine.Workspaces(0)
Set usr = wrk.Users(CurrentUser)
On Error GoTo Error_OK
usr.NewPassword Nz (Me.OldPassword, ""), Me.NewPassword
Set usr = Nothing
Set wrk = Nothing
 
End Sub
You haven't set a label Error_OK

this means it doesn't know where to go in the sub if an error occurs
 
Ok, how can I correct this?
It's oh so simple. Just add code to handle your error case.
Code:
Private Sub ChangePass_Click()
Dim usr As User
Dim wrk As Workspace
 
Set wrk = DBEngine.Workspaces(0)
Set usr = wrk.Users(CurrentUser)
On Error GoTo Error_OK
usr.NewPassword Nz (Me.OldPassword, ""), Me.NewPassword
Set usr = Nothing
Set wrk = Nothing
 
[COLOR=red]exit sub[/COLOR]
 
[COLOR=red]Error_OK: msgbox("I've got an ERRR!")[/COLOR]
 
 
End Sub
Obviously you'll need to put our own error handling in instead of my msgbox code
 

Users who are viewing this thread

Back
Top Bottom