Chazelle Consulting Services  

Contact Us

Home  |  Profile  |  Consultants |  References   

 

 

Home
 
Databases
Services
Resources
 
Web Design
Services
Portfolio
 
QuickBooks
Services
 
Office Automation
Services
 
Networking
Services
 
 
 

Password-Protect a Form

To protect any object with Access, you can use the Security features built-in in Access. However, they are cumbersome to implement as well as to use. You can implement your own limited security with these techniques.

To password-protect a form, do the following:

1. Create a table of Login names and associated passwords. This can easily be incorporated in a table of employees. We will assume this table to be called TblStaff, and the fields called "StaffLoginName" and "StaffPassword". The field StaffPassword can have a "password" input mask for security. Or those 2 fields could be created in a separate table that can then be hidden.

2. Create a table called "TblLoginRecords" to keep track of passwords entered as well as errors. This table would have the following fields:

LogStaffLoginName (text)
LogPasswordEntered (text)
LogTime (date/time)
LogDate (date/time)
LogProblem (Y/N)

3. Create a form named "frmLogin" with the table "TblLoginRecords" as record source.

4. On that form, create 4 textboxes with the LogStaffLoginName, LogPasswordEntered, LogTime and LogDate fields as Control Source. Also create a check box with the field LogProblem. Change the Visible property of LogPasswordEntered, LogTime and LogDate to No. Have LogTime default to time() and LogDate to date().

5. Create a button labeled "CmdLogin" with the following code attached to its OnClick property:

On Error GoTo Err_CmdLogin_Click

If [LogStaffLoginName] = DLookup("[StaffLoginName]", "TblStaff", "[StaffPassword]=forms!frmlogin!LogPasswordEntered") Then

DoCmd.OpenForm "FrmSwitchboard"

Else
Me!LogProblem = -1
DoCmd.Quit
End If

Forms!frmlogin.Visible = False

Exit_CmdLogin_Click:
Exit Sub

Err_CmdLogin_Click:
MsgBox Err.Description
Resume Exit_CmdLogin_Click

Note: The Login button will open a form called "Switchboard" with the correct password, and will quit Access if the password is incorrect. You could also record the date and time of login. The FrmLogin form should be open at Startup by using the Startup options, or should be the form to open before any form for which you want to check credentials.

As well, please note that you can hide the TblLoginRecords table by right-clicking on the table name, and selecting Hidden in the Property box (You will need to have "Hidden Objects" unchecked under the View tab of the Option menu).

Finally, it needs to be clear that anybody with good knowledge of Access would be able to bypass the Startup options and unhide any table. This type of security only protects against mistakes, not intentional malice by someone knowledgeable.