Protect a Microsoft Access Form with User Permissions
Question details
Restrict a form that edits usernames and passwords so only authorized users can open it.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user opens an account-management form from another form and wants to limit access based on the current user's permissions.
- Observed behavior
- The account-management form should open only for users with the appropriate authorization.
Confirm that your application identifies the logged-in user and that UserTb has a unique numeric UserID. The example below assumes the authenticated user's ID is stored in TempVars as CurrentUserID.
Check a User Permission When the Access Form Opens
Use a Yes/No field in the user table to control which users can open the account-management form.
The Form_Open check also runs when the form is opened from another form. It controls access through the application interface, but it is not a security boundary against someone who can directly modify the database or its code.
Open UserTb in Design View, add a Yes/No field named CanManageUsers, and save the table. Set the field to Yes only for users who should open the account-management form.
In your existing login procedure, set TempVars!CurrentUserID to the authenticated user's numeric UserID after authentication succeeds. Do not take the ID from an unverified user entry.
Open the protected form in Design View. In the Property Sheet, select the Event tab, set On Open to [Event Procedure], and click the builder button. Add this code to the form module: Private Sub Form_Open(Cancel As Integer) On Error GoTo DenyAccess If Not CBool(Nz(DLookup("CanManageUsers", "UserTb", "UserID=" & CLng(TempVars!CurrentUserID)), False)) Then GoTo DenyAccess End If Exit Sub DenyAccess: Cancel = True MsgBox "You are not authorized to open this form.", vbExclamation End Sub
Open the form from the calling form while logged in as a user with CanManageUsers set to Yes, then repeat with a user whose field is No. Confirm the second attempt displays the message and does not open the form.

Work with Office Documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office documents and spreadsheets. It can help you move common files between suites, but it does not replace Microsoft Access form permissions or fix Access security.

Frequently Asked Questions
How do I give one user permission to open the form?
Open UserTb and set CanManageUsers to Yes for that user's record. The Form_Open event can then look up the field using the authenticated user's UserID.
Will the Form_Open check run when another form opens the protected form?
Yes. The protected form's On Open event runs when it is opened, including through a button or a DoCmd.OpenForm call on another form.
Does a form permission check prevent users from accessing the underlying table?
No. A Form_Open check restricts the form interface, not direct access to the data. Enforce sensitive-data permissions in a secured backend and restrict access to database files and code.
What happens if the current user ID is missing?
In the example, a missing or invalid TempVars!CurrentUserID triggers the DenyAccess handler, which cancels the form opening. Set the ID only after the user has successfully authenticated.




