Others

Fix Microsoft Access Run-Time Error 2471 in a Login Form

Anum MushtaqAnum Mushtaq Nov 13, 2026 869 views

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.

Fix Microsoft Access Run-Time Error 2471 in a Login Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the login form module

In Microsoft Access, press Alt+F11 to open the VBA editor, then open the module or code behind the login form.

2
Locate the existing validation code

Find the current DLookup or login validation routine under the login button's Click event.

3
Replace with a combined DLookup

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 ...

4
Save and test the form

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.

Use a Single Combined DLookup to Validate Login Credentials
Cleaner login validation: A single DLookup with both criteria avoids independent lookups and returns only a matching login record.
Free Microsoft Office alternative

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. 1. Download WPS Office: Go to the official WPS Office website and click Download WPS Office Free.
  2. 2. Install and open WPS Office: Run the installer, then open WPS Office from the Start menu or Applications folder.
  3. 3. Open your existing Office files: Use the WPS Office home screen to open and edit Word, Excel, or PowerPoint files from your computer.
Free to download and use for daily documents, spreadsheets, and presentationsOpens and edits Microsoft Word, Excel, and PowerPoint files with strong format compatibilityFamiliar, lightweight interface that reduces the switch burden from Microsoft OfficeSeamless migration for everyday Office tasks without replacing Access database work
microsoft office alternative - wps office

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.