Fix Microsoft Access Run-Time Error 2471 in a Login Form
Question details
The user needs to resolve Microsoft Access Run-time error 2471 that appears when a login form evaluates a DLookup expression with an invalid criterion, an incorrect field reference, or an unexpected data type.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- The user is debugging or maintaining an Access login form that checks username and password credentials by using DLookup.
- Observed behavior
- Run-time error 2471 appears when the login form evaluates a DLookup expression with an invalid criterion, references an incorrect field, or evaluates a value with an unexpected data type.
Open the VBA module behind the login form and identify the exact DLookup expression that triggers the error. Have the target table and field names available so you can verify spelling and data types before editing the code.
Use a Single Combined DLookup to Validate Login Credentials
Use this solution when the login form should check both username and password together; it is safer than validating two fields independently.
A combined lookup returns one record only when both credentials match, so the form does not compare two separate DLookup results. Escape apostrophes in user input with Replace to avoid an invalid criterion.
In Microsoft Access, press Alt+F11 to open the VBA editor, then open the module or code behind the login form.
Find the current DLookup or login validation routine under the login button's Click event.
Replace the separate username and password checks with: If IsNull(DLookup("UserLoginNm","tblUserLogin","UserLoginNm='" & Replace(Me.txtUserLoginNm.Value,"'","''") & "' AND UserLoginPwd='" & Replace(Me.txtUserLoginPwd.Value,"'","''") & "'")) Then MsgBox "Invalid credentials" Else ...
Save the VBA project, switch back to Access, open the login form, and enter valid and invalid credentials to confirm the error no longer occurs.

Test Each DLookup Part Separately to Find the Faulty Criterion
Use this diagnostic approach when you need to isolate whether the username lookup, password lookup, or a field name is causing Run-time error 2471.
Use WPS Office as a Free Alternative for Everyday Office Tasks While Access Handles Databases
WPS Office does not include a Microsoft Access equivalent, so it cannot directly repair Access VBA Run-time error 2471. For daily documents, spreadsheets, and presentations, WPS Office is a free, lightweight alternative that opens Microsoft Word, Excel, and PowerPoint files with a familiar interface and smooth migration.
- 1. Download WPS Office: Go to the official WPS Office website and click Download WPS Office Free.
- 2. Install and open WPS Office: Run the installer, then open WPS Office from the Start menu or Applications folder.
- 3. Open your existing Office files: Use the WPS Office home screen to open and edit Word, Excel, or PowerPoint files from your computer.

Frequently Asked Questions
What causes Run-time error 2471 in an Access login form?
It usually occurs when a DLookup criterion is invalid, references an incorrect field, or compares a value with an unexpected data type. Check the table name, field names, and control values in the expression.
How do I test a DLookup expression separately?
Open the Access VBA editor with Alt+F11, press Ctrl+G to open the Immediate Window, and run a test such as ?DLookup("UserLoginNm","tblUserLogin","UserLoginNm='" & [Forms]![YourLoginForm]![txtUserLoginNm] & "'"). Then repeat for the password field.
Should I validate username and password separately or together?
A safer design is to use one DLookup with both criteria in the same expression. This returns a record only when both values match and avoids comparing two independent lookups.
How do I escape apostrophes in a DLookup criterion?
Wrap text input with Replace(Me.ControlName.Value, "'", "''") before inserting it into the criterion so an apostrophe in the entered value does not break the expression.
Can WPS Office open or repair Microsoft Access databases?
No, WPS Office does not include an Access equivalent and does not open .accdb or .mdb database files. It is a free alternative for Word, Excel, and PowerPoint files, while Microsoft Access remains necessary for Access VBA forms and linked data tasks.




