How to Fix Microsoft Access Login Form and Set User-Level Permissions
Question details
The user needs to fix an Access login form that opens the main form even with an invalid password, and configure user-level permissions so Level 1 users can edit while others have read-only access.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Securing a database application with a custom login form and role-based access control.
- Observed behavior
- The login form incorrectly bypasses security by opening the main form upon entry of an invalid password, and it lacks proper user-level permission enforcement.
Ensure you have a backup of your Access database (.accdb or .mdb) before modifying VBA code or macros, and verify that your user table contains fields for both passwords and permission levels.
Validate Password and Assign Permissions Using VBA
Use a combo box to select the user and a VBA If statement to validate the password and apply user-level permissions before opening the main form.
By utilizing the Column property of a combo box, you can easily retrieve hidden values like passwords and access levels without running complex queries. An If statement is then used to compare the entered password with the stored password.
Open your login form in Design View. Ensure your user selection field is a Combo Box that pulls data from your Users table. It should include columns for UserID, Password, and AccessLevel. Set the Column Widths to hide the password and access level (e.g., 1";0";0").
Right-click the 'Login' button on your form, select 'Build Event', and choose 'Code Builder' to open the VBA editor.
Add an If statement to compare the entered password with the Combo Box's hidden password column. For example: `If Me.txtPassword = Me.cboUser.Column(1) Then`.
Inside the If block, check the AccessLevel column (e.g., `Me.cboUser.Column(2)`). If the level is 1, use `DoCmd.OpenForm "MainForm", , , , acFormEdit`. Else, use `acFormReadOnly`.
Add an `Else` statement to display an error message (using `MsgBox`) if the password does not match, ensuring the main form does not open.

Looking for a reliable and free alternative to Microsoft Office?
While Microsoft Access is specialized for database management, many of your daily document, spreadsheet, and presentation tasks can be handled efficiently with WPS Office. It provides a lightweight, free alternative that is highly compatible with Microsoft Word, Excel, and PowerPoint.
- 1. Download WPS Office: Visit the official WPS website and click the free download button for your operating system.
- 2. Install the Suite: Run the downloaded installer and follow the simple on-screen instructions to set up WPS Office on your device.
- 3. Open Your Files: Launch WPS Office and directly open your existing Word, Excel, or PowerPoint files to experience seamless compatibility.

Frequently Asked Questions
Why does my Access main form open even if the password is wrong?
This usually happens when the macro or VBA code attached to the login button triggers the 'OpenForm' command without a proper conditional check (If statement) to verify that the entered password exactly matches the stored password.
How do I make an Access form read-only for specific users?
You can use the DataMode argument in the DoCmd.OpenForm method in VBA. By passing 'acFormReadOnly' when a user with restricted permissions logs in, the form will prevent them from editing the data.
Can I use macros instead of VBA for an Access login form?
Yes, you can use the Macro Builder to create an 'If' block that compares the password text box to the user table's password field. However, VBA generally offers more flexibility for handling multiple user permission levels securely.




