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
word. 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]