Security checking module not referencing form variables

naminder

Registered User.
Local time
Today, 21:21
Joined
Aug 8, 2005
Messages
41
I have written a module that can be called from a form on open event. It checks for a correct password. I want the code to set different permissions on the form as it opens.

The AllowAdditions line returns run time error

Public Sub RestrictedArea()

Dim strPasswd

strPasswd = InputBox("Enter Password", "This is a Restricted Area")

'Check to see if there is any entry made to input box, or if
'cancel button is pressed. If no entry is made then exit sub.
If strPasswd = "" Or strPasswd = Empty Then
MsgBox "You left the box blank, try again!", vbInformation, "Required Data"
DoCmd.Close
Exit Sub
End If

'If correct password is entered open
'If incorrect password entered give message and then exit sub
If strPasswd = "nam" Then

AllowAdditions = False
'AllowDeletions = False
'Continue to open Access Granted

Else
MsgBox "Sorry, you do not have access to this area", vbOKOnly, "Important Information"
DoCmd.Close
Exit Sub
End If

End Sub
 
what is the run time error that you get?

remember that if you want to create a variable that is accessible across different subs/forms you need to make it a public variable by going into a module, and before any code, write something like
Code:
Public AllowAdditions as Boolean

then this will be accessible by all code throughout the run of the program.
 
My code was ALL wrong. I needed to pass variables to the form.

This is my latest code, still working to see if I can put anymore security in.

I call the function from the form onload by using

Private Sub Form_Load()

Call RestrictedArea(Me)

End Sub

-------------------------------Module

Function RestrictedArea(frm As Form)

Dim strPasswd

strPasswd = InputBox("Enter Password", "This is a Restricted Area")

Select Case strPasswd

Case ""
MsgBox "You left the box blank, try again!", vbInformation, "Required Data"
DoCmd.Close
Exit Function

Case "readonly"
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With

Case "dataentry"
With frm
.AllowAdditions = True
.AllowEdits = False
.AllowDeletions = False
End With

Case "admin"
With frm
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
End With

Case Else
MsgBox "Sorry, you do not have access to this area", vbOKOnly, "Important Information"
DoCmd.Close
Exit Function
End Select

End Function
 

Users who are viewing this thread

Back
Top Bottom