Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password "Delete Current Record" command button 1

Status
Not open for further replies.

Autoeng

Technical User
Jul 16, 2002
57
US
I would appreciate any help anyone could offer as to adding a password to a command button for deleting the current record. I would like to add a command button to my form so that you can delete the current displayed record but when someone clicks it, it asks for password before firing the actual delete.

Thanks in advance
 
Hey AutoEng - try this in the 'on click' of your command button. It will allow 3 incorrect tries at the password before booting the user out of the application. If you want a different outcome to repeated incorrect attempts then change the 'docmd.quit' to something else. The password itself is contained in the code, in this example it is 'CHRIS' (This is NOT case sensitive).

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim x As Integer
For x = 1 To 3
Dim strInput As String, strMsg As String
strMsg = "Enter Delete Password"
strInput = InputBox(prompt:=strMsg, title:="Password Required", xpos:=2000, ypos:=2000)
If strInput = "CHRIS" Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit Sub
Else
Dim msg, style, title, response
msg = "Password Incorrect"
style = vbOKOnly + vbExclamation
title = "Password error"
response = MsgBox(msg, style, title)
End If
Next x
DoCmd.Quit
Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub
------------------------------------------------------------
Hope this helps
Chris
 
hi

i think the best way is to have a table containing username and password, when the user press the delete button, open a form in modal mode (call dialog in Access) and ask for username and password (or only password if you prefer). Cross-check with the table, if the password is valid, execute the delete

Mal'chik [bigglasses]
 
Krispi's suggestion was the one that I was looking for. Thank you very much, it works great. However, when I distributed the front end again the first thing said was, "Oh s***, not another password to remember". As there are only two individuals that can delete records would it be possible to change the code to look at ()CurrentUser to see if it matched one of the two people authorized to delete and if it did then fire the delete without a password?

Again, thanks for the help.

Autoeng
 
Wow Autoeng, you went with the more coplicated version. I like to see that in a programmer. If you were concerned about only certain people doing the operation, you could have included a check on employee types and only allowed certain employee types to delete records. Malchik's is the solution I use for password entry, its clean and clear and works very well; and it's so simple you can come up with it yourself just by thinking.
 
I did find one problem with Krispi's code. There is no out. If you decide, Oh I'm in the wrong place, and select cancel the code just keeps on running until after the third try you are kicked out of the database. When I find the solution, or if someone knows the solution, please post it for others.
 
Hi!

First to answer your question, just remove the DoCmd.Quit and the user will just be back in the form instead of out of Access altogether. A couple of things to note:

1.) The input box isn't the best way to ask for passwords because you can't format it to display only astericks. Anyone walking by could get the password to delete records.

2.) You can check the user name using CurrentUser() (if you don't get anything back from CurrentUser post back for code to get the username) and use that to check for permission. The best way is to check for user permission and then ask for a password also, using a modal form like the suggestion from Malchik. This will allow you the easiest methods for updating since you will be maintaining a table and it will allow you to force the user to change their password regularly just by keeping a last changed date field.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Jeff Bridgham

Answer to number 1. Yes you can set the field to display only astericks. You set the input mask to "password."

Answer to number 2. I don't understand your code anyways.. its much to complicated for me. So I refuse to reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top