Report Protection

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I've created a database with a few forms and reports that
open when a command button is pressed. Is there a way to
protect the button so that when pressed a password must be
entered in order for the user to have access to the form
or report that opens? Any comments would be appreciated.

Thx
 
Eric said:
I've created a database with a few forms and reports that
open when a command button is pressed. Is there a way to
protect the button so that when pressed a password must be
entered in order for the user to have access to the form
or report that opens? Any comments would be appreciated.

Have a look at this Knowledge Base article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;179371
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
-----Original Message-----
I've created a database with a few forms and reports that
open when a command button is pressed. Is there a way to
protect the button so that when pressed a password must be
entered in order for the user to have access to the form
or report that opens? Any comments would be appreciated.

Thx
.
It's close to working, but it doesn't seem to go to the
password table to check the password when I enter it.
Here's the code:

Public Function KeyCode(Password As String) As Long
' This function will produce a unique key for the
' string that is passed in as the Password.
Dim I As Integer
Dim Hold As Long

For I = 1 To Len(Password)
Select Case (Asc(Left(Password, 1)) * I) Mod 4
Case Is = 0
Hold = Hold + (Asc(Mid(Password, I, 1)) * I)
Case Is = 1
Hold = Hold - (Asc(Mid(Password, I, 1)) * I)
Case Is = 2
Hold = Hold + (Asc(Mid(Password, I, 1)) * _
(I - Asc(Mid(Password, I, 1))))
Case Is = 3
Hold = Hold - (Asc(Mid(Password, I, 1)) * _
(I + Len(Password)))
End Select
Next I
KeyCode = Hold
End Function


Private Sub Report_Open(Cancel As Integer)
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As Recordset
Dim db As Database

On Error GoTo Error_Handler
' Check to see if the user is passing in the
Password.
Hold = InputBox("Please Enter Your
Password", "Enter Password")
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword",
dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password info.
Please Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the
key in
' the table; if there is not a match, stop the
form
' from opening.
If Not (rs![KeyCode] = KeyCode(CStr(Hold)))
Then
MsgBox "Sorry you entered the wrong
password. " & _
"Please try again.",
vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub

Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" &
Err.Number
Exit Sub
End Sub

The public one is saved as a module called mdlPassword,
the private one is on the report's open properties, the
mdlPassword module shows up at the top when I open
properties of the report, I can't seem to find anything
wrong with the code, It asks for a password, I put it in,
and it says that it isn't correct.
 
I have it working now Thank you very much for the info.

-----Original Message-----
-----Original Message-----
I've created a database with a few forms and reports that
open when a command button is pressed. Is there a way to
protect the button so that when pressed a password must be
entered in order for the user to have access to the form
or report that opens? Any comments would be appreciated.

Thx
.
It's close to working, but it doesn't seem to go to the
password table to check the password when I enter it.
Here's the code:

Public Function KeyCode(Password As String) As Long
' This function will produce a unique key for the
' string that is passed in as the Password.
Dim I As Integer
Dim Hold As Long

For I = 1 To Len(Password)
Select Case (Asc(Left(Password, 1)) * I) Mod 4
Case Is = 0
Hold = Hold + (Asc(Mid(Password, I, 1)) * I)
Case Is = 1
Hold = Hold - (Asc(Mid(Password, I, 1)) * I)
Case Is = 2
Hold = Hold + (Asc(Mid(Password, I, 1)) * _
(I - Asc(Mid(Password, I, 1))))
Case Is = 3
Hold = Hold - (Asc(Mid(Password, I, 1)) * _
(I + Len(Password)))
End Select
Next I
KeyCode = Hold
End Function


Private Sub Report_Open(Cancel As Integer)
Dim Hold As Variant
Dim tmpKey As Long
Dim I As Integer
Dim rs As Recordset
Dim db As Database

On Error GoTo Error_Handler
' Check to see if the user is passing in the
Password.
Hold = InputBox("Please Enter Your
Password", "Enter Password")
' Open the table that contains the password.
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPassword",
dbOpenTable)
rs.Index = "PrimaryKey"
rs.Seek "=", Me.Name
If rs.NoMatch Then
MsgBox "Sorry cannot find password info.
Please Try Again"
Cancel = -1
Else
' Test to see if the key generated matches the
key in
' the table; if there is not a match, stop the
form
' from opening.
If Not (rs![KeyCode] = KeyCode(CStr(Hold)))
Then
MsgBox "Sorry you entered the wrong
password. " & _
"Please try again.",
vbOKOnly, "Incorrect Password"
Cancel = -1
End If
End If
rs.Close
db.Close
Exit Sub

Error_Handler:
MsgBox Err.Description, vbOKOnly, "Error #" &
Err.Number
Exit Sub
End Sub

The public one is saved as a module called mdlPassword,
the private one is on the report's open properties, the
mdlPassword module shows up at the top when I open
properties of the report, I can't seem to find anything
wrong with the code, It asks for a password, I put it in,
and it says that it isn't correct.

.
 
Back
Top