ALTER USER STATEMENT

G

Guest

I found this code as an example of how to impement the ALTER USER statement
in my program. I'm not sure how to do this. It looks as though I'd place this
behind a form with the with text boxes. Can anyone help me with this, it
would be greatly appreciated.

Thanks Rob


Sub NewPasswordX()
On Error GoTo errorpass
Dim WrkDefault As Workspace
Dim usrNew As User
Dim grpNew As Group
Dim grpMember As Group
Dim strPassword As String, oldPassword As String
' Get default workspace.
Set WrkDefault = DBEngine.Workspaces(0)
With WrkDefault
' Create and append new user.
Set usrNew = .Users(CurrentUser)
' Ask user for new password. If input is too long, ask again.
Do While True
oldPassword = InputBox("Enter old password:" &
vbCrLf & "(Remember that passwords are case sensitive.
Check that your CAPS LOCK key is OFF, and if your password
contains numbers, that the NUM LOCK key is ON.)", "Old
Password")
strPassword = InputBox("Enter new password:" &
vbCrLf & "(Remember that passwords are case sensitive.
Check that your CAPS LOCK key is OFF, and if your password
contains numbers, that the NUM LOCK key is ON.)", "New
Password")
Select Case Len(strPassword)
Case 1 To 14
usrNew.NewPassword oldPassword,
strPassword
MsgBox "Password changed!",
vbInformation, "Success"
Exit Do
Case Else
MsgBox "New password too long (14
characters maximum), or contains invalid characters." &
vbCrLf & "Password was not changed.", vbCritical, "Failure"
Exit Do
End Select
Loop
End With
Exit Sub
errorpass:
If Err.Number = 3033 Then
MsgBox "The old password you supplied is
incorrect. The password was not changed.",
vbInformation, "Failure"
Exit Sub
Else
MsgBox Err.Description & vbCrLf & "Error Number: "
& Err.Number
Exit Sub
End If
End Sub
 
6

'69 Camaro

Hi, Rob.
I found this code as an example of how to impement the ALTER USER statement
in my program.

Uh, you asked yesterday how to use the ALTER USER statement, and I gave you
the syntax. The code below doesn't ALTER USER, but it does change the
password if the user offers both a valid old password and new password,
which is what you're after. But since you're having trouble implementing
it, why not keep it as simple as possible?

The easiest way to allow the user to change his own password is by putting a
button on a form, place [Event Procedure] in the button's OnClick( ) event,
and paste the following code in the form's module, ensuring the name of the
button matches what is currently ChgUsersPswdBtn in this example, then save
and compile the code.

Private Sub ChgUsersPswdBtn_Click()

On Error GoTo ErrHandler

SendKeys "^+{TAB}", False
RunCommand acCmdUserAndGroupAccounts

Exit Sub

ErrHandler:

MsgBox "Error in ChgUsersPswdBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub ' ChgUsersPswdBtn_Click( )

Open the form in Form View and select the button to open the Change Logon
Password dialog window. The user will be able to change his password with
the built-in dialog window, so you needn't write code to verify the old and
new password's validity and warn the user.

Is this easier for you?

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
G

Guest

thank you so very much. perfect. Have a great day. Rob

'69 Camaro said:
Hi, Rob.
I found this code as an example of how to impement the ALTER USER statement
in my program.

Uh, you asked yesterday how to use the ALTER USER statement, and I gave you
the syntax. The code below doesn't ALTER USER, but it does change the
password if the user offers both a valid old password and new password,
which is what you're after. But since you're having trouble implementing
it, why not keep it as simple as possible?

The easiest way to allow the user to change his own password is by putting a
button on a form, place [Event Procedure] in the button's OnClick( ) event,
and paste the following code in the form's module, ensuring the name of the
button matches what is currently ChgUsersPswdBtn in this example, then save
and compile the code.

Private Sub ChgUsersPswdBtn_Click()

On Error GoTo ErrHandler

SendKeys "^+{TAB}", False
RunCommand acCmdUserAndGroupAccounts

Exit Sub

ErrHandler:

MsgBox "Error in ChgUsersPswdBtn_Click( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub ' ChgUsersPswdBtn_Click( )

Open the form in Form View and select the button to open the Change Logon
Password dialog window. The user will be able to change his password with
the built-in dialog window, so you needn't write code to verify the old and
new password's validity and warn the user.

Is this easier for you?

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


RobUCSD said:
I found this code as an example of how to impement the ALTER USER statement
in my program. I'm not sure how to do this. It looks as though I'd place
this
behind a form with the with text boxes. Can anyone help me with this, it
would be greatly appreciated.

Thanks Rob


Sub NewPasswordX()
On Error GoTo errorpass
Dim WrkDefault As Workspace
Dim usrNew As User
Dim grpNew As Group
Dim grpMember As Group
Dim strPassword As String, oldPassword As String
' Get default workspace.
Set WrkDefault = DBEngine.Workspaces(0)
With WrkDefault
' Create and append new user.
Set usrNew = .Users(CurrentUser)
' Ask user for new password. If input is too long, ask again.
Do While True
oldPassword = InputBox("Enter old password:" &
vbCrLf & "(Remember that passwords are case sensitive.
Check that your CAPS LOCK key is OFF, and if your password
contains numbers, that the NUM LOCK key is ON.)", "Old
Password")
strPassword = InputBox("Enter new password:" &
vbCrLf & "(Remember that passwords are case sensitive.
Check that your CAPS LOCK key is OFF, and if your password
contains numbers, that the NUM LOCK key is ON.)", "New
Password")
Select Case Len(strPassword)
Case 1 To 14
usrNew.NewPassword oldPassword,
strPassword
MsgBox "Password changed!",
vbInformation, "Success"
Exit Do
Case Else
MsgBox "New password too long (14
characters maximum), or contains invalid characters." &
vbCrLf & "Password was not changed.", vbCritical, "Failure"
Exit Do
End Select
Loop
End With
Exit Sub
errorpass:
If Err.Number = 3033 Then
MsgBox "The old password you supplied is
incorrect. The password was not changed.",
vbInformation, "Failure"
Exit Sub
Else
MsgBox Err.Description & vbCrLf & "Error Number: "
& Err.Number
Exit Sub
End If
End Sub
 
6

'69 Camaro

Hi, David.
Does that work in the Runtime?

Yes. I just now tested it in Access 2003 with the Runtime switch, and I
believe I tested it way back when in Access 2000 with the Runtime switch as
well. I don't doubt that it will work in Access 2002, also. I have no way
of testing it in the Access 97 Runtime, because that version didn't have the
Runtime switch to simulate the Runtime version. So I'll let someone else
test that if he's so inclined and report back here of his findings.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top