Set password on a control

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?
 
T

Tom van Stiphout

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
 
J

Jennifer

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
 
J

Jennifer

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".
 
D

Douglas J. Steele

Show us what you changed the code to.

For the wrong password message, you'd put an Else clause in the If
statement.
 
J

Jennifer

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
 
D

Douglas J. Steele

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
 
J

Jennifer

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.
 
D

Douglas J. Steele

How are you determining that the record has been deleted? What happens if
you click No instead of Yes?
 
J

Jennifer

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!
 

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