To do it right, you need to set up user level security and maybe mess with
the query's Run Permissions property. That's quite a bit of work.
If you want to put a password on it without all the trouble of user level
security, modify the code below:
'-----
Private Sub Run_Query_Click()
On Error GoTo Err_Run_Query_Click
Dim Message, Title, Default, MyValue, stDocName
Message = "Enter Password" ' Set prompt.
Title = "Password" ' Set title.
stDocName = "qryJay" ' Set query
MyValue = InputBox(Message, Title)
If MyValue = "Password" Then
DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
Else
MsgBox "Wrong Password. Try again."
End If
Exit_Run_Query_Click:
Exit Sub
Err_Run_Query_Click:
MsgBox Err.Description
Resume Exit_Run_Query_Click
End Sub
'-----
Know that there are many, many ways to bypass this password such as going to
the database window and running the query there; going into the tables and
deleting the records directly; or opening up this form in design view and
finding the password.