Password question

  • Thread starter Thread starter Alberta Rose
  • Start date Start date
A

Alberta Rose

I have a switchboard with three buttons on it. I would like to password
protect one of the buttons because it is for administrator use only. How do
I do this?

Thanks.
 
On Wed, 15 Apr 2009 07:12:08 -0700, Alberta Rose

How strong do you want the protection to be? If minimal, how about
this one-liner in Form_Open event of that protected form (NOT the
button):
Cancel = (InputBox("Yo! Gimme your password") <> "secret")

-Tom.
Microsoft Access MVP
 
Tom,
I tried this, but it did not work. I received an error message "The object
doesn't contain the Automation object 'Cancel'

I am using Access 2007, and this is exactly what I need to protect a few of
the reports in my database. My users are content with not understanding the
works of the db so don't explore as long as I make it pretty for them :)
However I do have a few reports that only one person should be able to
access. I think your advice is what I need if I can get it to work.
Thanks
Jacqueline
 
Thanks, this looks scary, but I will work through it. I will let you know if
it work... :)
Jacqueline

Afrosheen via AccessMonster.com said:
Hi Jacqueline. It's a pleasure to finally get to help someone after all the
help I've gotten here. This is a program I've been using. It takes the
password and stores the information in another table so you can see who's
been in there. Here are the stats.

Create a new form call it: frmPass

On the form Record Source select tblPass

Create an Unbound text box and name it: username. Input Mask: Password. Note
The text for the username would be UserID:

Create another Unbound text box and name it:Pword. Inpaut Mask: Password.
Note: Name the text: Password:

Create two tables:
Table 1
tblPass
Key: AutoNnumber
User: Text
Password: Text
UserLevel: Number
Name: Text

Table 2
tblPassLog
Id: AutoNumber
Date: Date/Time
Time: Date/Time
User: Text
Uname: Text
PrgName: Text

Now, Here is the code:

Private Sub Pword_AfterUpdate()
Dim pname As String
Dim I As Integer
Dim rst As DAO.Recordset ' The tLogError table
10 strUser = username

Static counter As Integer
20 If StrComp(Me.Pword, Nz(DLookup("Password", "tblpass", "User=" & """" &
strUser & """"), ""), 0) = 0 Then
30 userpermission = DLookup("[userlevel]", "[tblpass]", "[User] = '" &
strUser & "'")
40 pname = DLookup("[name]", "[tblpass]", "[User] = '" & strUser & "'")
50 If userpermission = 3 Then
60 Call MsgBox("Your security level is not high enough to continue.
", vbCritical, "Access Denied")
70 DoCmd.Close acForm, "frmpass"
80 Exit Sub
90 Else
100 strUser = ""
110 username = ""
120 Pword = ""
130 End If

140 Set rst = CurrentDb.OpenRecordset("tPassLog", , dbAppendOnly)
150 rst.AddNew
160 rst![Date] = Date
170 rst![User] = strUser
180 rst![Time] = Time()
190 rst![Uname] = pname
200 rst![prgname] = "FrmPass"
210 rst.Update
220 rst.Close

230 DoCmd.Close acForm, "frmpass" 'Closes the password window

' ***************** Show or Hide the Table Window ***************
'To show the database window, run
240 DoCmd.SelectObject acTable, , True

'To Hide the database window, run
'DoCmd.SelectObject acTable, , True
'DoCmd.RunCommand acCmdWindowHide

250 For I = 1 To CommandBars.Count
260 CommandBars(I).Enabled = True
270 Next I

280 DoCmd.Close acForm, "Your form you want to close"
290 Exit Sub

300 Else
310 If counter < 2 Then
320 Call MsgBox("Oh Oh! You Didn't Say the Magic Word!!" _
& vbCrLf & "" _
& vbCrLf & "You Only Get 3 Times To Get It Right" _
, vbCritical, Application.Name)

330 strUser = ""
340 username = ""
350 Pword = ""
360 counter = counter + 1
370 Else
380 DoCmd.Close acForm, "Your Form Name"
390 End If
400 End If

End Sub


What this will do is check the user level of the program and close the
program. Then store the information in the pass log table.

Good Luck. Let me know if it works for you.


Tom,
I tried this, but it did not work. I received an error message "The object
doesn't contain the Automation object 'Cancel'

I am using Access 2007, and this is exactly what I need to protect a few of
the reports in my database. My users are content with not understanding the
works of the db so don't explore as long as I make it pretty for them :)
However I do have a few reports that only one person should be able to
access. I think your advice is what I need if I can get it to work.
Thanks
Jacqueline
How strong do you want the protection to be? If minimal, how about
this one-liner in Form_Open event of that protected form (NOT the
[quoted text clipped - 9 lines]
 
On Fri, 17 Apr 2009 10:40:01 -0700, Jacqueline

I am in A2007 too, although that does not matter for this situation.
The error tells me you were not in the Form_Open event. Please check
again, or post your code.

Private Sub Form_Open(Cancel As Integer)
Cancel = (InputBox("Yo! Gimme your password") <> "secret")
End Sub

-Tom.
Microsoft Access MVP
 
Tom,
You were correct, I had the code in the wrong place. I was trying to use the
reports properties event, rather than VB Report_Open. It works now thanks
Jacqueline
 
Hi Tom. Here is the coding for the button I want to protect. Where in it
should I add the coding as you suggested.

Your Suggestion:

Private Sub Form_Open(Cancel As Integer)
Cancel = (InputBox("Yo! Gimme your password") <> "secret")
End Sub


My Buttons Coding:

Private Sub cmdForms_Click()
On Error GoTo Err_cmdForms_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInput"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdForms_Click:
Exit Sub

Err_cmdForms_Click:
MsgBox Err.Description
Resume Exit_cmdForms_Click

End Sub
 
Hi Alberta,
This came to me not Tom, however I think I can answer your question. My
report is also accessed from a button, but I did not protect the button, I
protected the report.

If you open your report in design view, click on the VIEW CODE tool, either
on the design tab or if you are not in 2007 I believe it is in your Tools
menu.

With the VB Code window open, paste in the following code from Tom:

Private Sub Report_Open(Cancel As Integer)
Cancel = (InputBox("Please enter your password") <> "your password here")
End Sub

close the code window.

Anyone can access the button, however if they do nto have the password they
will not be able to access the report, or form... depending on where you are
using this.
Hope this helps, if not be sure to reply to Tom so he will get the email. :)
Jacqueline
 
Hi Tom. Here is the coding for the button I want to protect. Where in it
should I add the coding as you suggested.

Your Suggestion:

Private Sub Form_Open(Cancel As Integer)
Cancel = (InputBox("Yo! Gimme your password") <> "secret")
End Sub


My Buttons Coding:

Private Sub cmdForms_Click()
On Error GoTo Err_cmdForms_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmInput"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdForms_Click:
Exit Sub

Err_cmdForms_Click:
MsgBox Err.Description
Resume Exit_cmdForms_Click

End Sub
 
Back
Top