Professional Documents
Culture Documents
Answer » The following details one procedure that could be applied to this scenario.
There are many more approaches to this and also other areas that will need to be
secured within your database environment. On initially opening the Microsoft
Access database you are presented with a database LogOn screen. This screen
controls security access to the database and its objects. You should set the LogOn
form to be the first form to open in the database start-up options.
The screen seen below is an unbound form containing an unbound drop -down list.
This list is made up of users defined in the table - tblEmployees.
The other control on the form is an unbound text box. This control is where the user
will enter their security password. This control also contains an input mask ensuring
that their password cannot be seen: (***********)
The form then contains a command button labelled Go. There is visual basic code
contained on the On Click event of this button that will ensure access to the
database providing valid information is entered into the above controls. You can see
the LogOn form below:
The user will then need to enter their valid password, followed by clicking the
command button to enter the database.
On clicking the command button (cmdLogin) the following code is attached to the
buttons On Click event procedure:
Private Sub cmdLogin_Click()
lngMyEmpID = Me.cboEmployee.Value
If a selection has not been made the user will be presented with a message box informing that
this is required data, clicking OK will send the focus to the combo box:
Once a selection is made the focus moves to the password entry control. Once again this uses a
statement to check that an entry is made:
Once the required information is entered the following code runs to validate the entries made:
lngMyEmpID = Me.cboEmployee.Value
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
If the information contained matches information found in tblEmployees the user will then be
allowed access to the database, and the database splash screen will appear.
The final statement executed by the code will check to see if an incorrect password has been
entered 3 times. If this is found to be true, the user is presented with a message box informing
them of the situation and the database will close:
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
Finally, you will need to create a module to store the following variable: