Set password on a control

  • Thread starter Thread starter Jennifer
  • Start date Start date
J

Jennifer

I would like to add a control to a form that will delete the record. Can I
set a password on the control so only a couple of people can actually use it?
 
On Thu, 27 Aug 2009 06:25:02 -0700, Jennifer

Sure. Say this "control" is a button. In its Click event write:
if InputBox("What's the Password?") = "secret" then
'your code to delete the record goes here.
end if

-Tom.
Microsoft Access MVP
 
This is what I have set. It is prompting for a password and then deleting
whether the password is entered or not.

Private Sub Command492_Click()
On Error GoTo Err_Command492_Click
If InputBox("What's the Password?") = "secret" Then
'your code to delete the record goes here.
End If


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command492_Click:
Exit Sub

Err_Command492_Click:
MsgBox Err.Description
Resume Exit_Command492_Click

End Sub
 
Fixed it BUT is deleting the record before it confirms the deletion. I want
it to prompt for the password and then wait until you confirm to delete.
Also, if it is the wrong password to say "you are not authroized to perform
this function".
 
Show us what you changed the code to.

For the wrong password message, you'd put an Else clause in the If
statement.
 
Private Sub Command492_Click()
On Error GoTo Err_Command492_Click
If InputBox("What's the Password?") = "secret" Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

End If
Exit_Command492_Click:
Exit Sub

Err_Command492_Click:
MsgBox Err.Description
Resume Exit_Command492_Click

End Sub
 
There's no way that code should be deleting the record before the prompt for
the password.

To get the warning that they've entered an incorrect password, have
something like

Private Sub Command492_Click()
On Error GoTo Err_Command492_Click
If InputBox("What's the Password?") = "secret" Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
MsgBox "Password was incorrect."
End If

Exit_Command492_Click:
Exit Sub

Err_Command492_Click:
MsgBox Err.Description
Resume Exit_Command492_Click

End Sub
 
It is not deleting before the password. As soon as you put the password in
it deletes the record THEN you get the pop up box "you are about to delete 1
record - Click yes to continue". But the record has already been deleted
and clicking yes does nothing.
 
How are you determining that the record has been deleted? What happens if
you click No instead of Yes?
 
Okay, if I click no it does not delete. Just the initial panic of seeing it
disappear before I confirm. All is good... thank you!
 
Back
Top