VBA & Macro Problems

Fix Microsoft Access VBA Error 2427 When Checking Null and Blank Form Values

Muhammad TalhaMuhammad Talha Nov 13, 2026 869 views

Question details

The user needs to correct an Access form expression that checks Null and blank values and enables a command button only when the required conditions are met.

Fix Microsoft Access VBA Error 2427 When Checking Null and Blank Form Values
Product
Microsoft Access VBA
Device & OS
not provided
Scenario
A form uses LockedWho1 and LockedWho2 to determine whether a command button should be enabled.
Observed behavior
Access reports error 2427 because an expression has no value. The existing expression also uses a greater-than comparison to determine whether text is nonblank.
Before you start

Open the form in Design View and confirm that LockedWho1, LockedWho2, and Command6 are the actual control names in the Property Sheet. Identify the event that runs the expression and check whether the form has a current record when it executes.

Solution 1Recommended

Use explicit control references and separate Null from blank checks

Use this correction when the form controls have readable values but the condition handles Null or blank text incorrectly.

Null, an empty string, and whitespace-only text are different values. IsNull checks for Null, while Len(Trim(value & vbNullString)) > 0 checks for nonblank text after treating Null as an empty string.

Error 2427 means the expression has no value; a readable control containing Null is not necessarily the cause. These checks handle Null values, but they cannot make an unavailable control value readable.

1
Open the form's VBA procedure

In Access, open the form in Design View, select the form or relevant control, and open the Event tab in the Property Sheet. Click the build button (...) beside the event containing the failing expression to open its VBA procedure.

2
Replace the condition

Use explicit references to the controls: If IsNull(Me!LockedWho2.Value) And Len(Trim(Me!LockedWho1.Value & vbNullString)) > 0 Then. This condition requires LockedWho2 to be Null and LockedWho1 to contain nonblank text.

3
Set the button state in both branches

If Command6 is the button that should be enabled for that condition, use: If IsNull(Me!LockedWho2.Value) And Len(Trim(Me!LockedWho1.Value & vbNullString)) > 0 Then Me!Command6.Enabled = True Else Me!Command6.Enabled = False End If Replace Command6 with the intended button name if necessary. Review any other button assignments so they match the required conditions.

4
Test the relevant value combinations

Switch to Form View and test records where LockedWho1 is Null, an empty string, spaces only, and ordinary text. Also test LockedWho2 with both Null and a populated value. Command6 should be enabled only when LockedWho2 is Null and LockedWho1 contains nonblank text.

Use explicit control references and separate Null from blank checks
Decide whether LockedWho2 may also be blank: IsNull(Me!LockedWho2.Value) does not match an empty string or spaces. If the requirement treats all of those as empty, replace that check with Len(Trim(Me!LockedWho2.Value & vbNullString)) = 0.
Free Microsoft Office alternative

Use WPS Office for Documents and Spreadsheets Alongside Access

WPS Office does not repair Access VBA error 2427 or replace Access database forms. For related documents, spreadsheets, and presentations, it offers a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for easy migration.

Work with Access data exported to Excel-compatible spreadsheets.Open and edit Microsoft Excel .xlsx, Word .docx, and PowerPoint .pptx files.Use a familiar Office-style interface for everyday editing.Keep Access for database forms and VBA while using WPS for supporting files.
microsoft office alternative - wps office

Frequently Asked Questions

Is a Null control value always the cause of Access error 2427?

No. Error 2427 means the expression has no value, which can occur when a bound control has no usable current record. A readable Null value can be tested with IsNull. Check both the control reference and the event timing.

Why not use LockedWho1 <> "" to check for nonblank text?

That comparison does not handle Null reliably and treats spaces as text. Use Len(Trim(Me!LockedWho1.Value & vbNullString)) > 0 to reject Null, empty strings, and text containing only ordinary spaces.

Should the button logic run in Form_Load or Form_Current?

Use Form_Load for an initial check after the form loads. Use Form_Current when the button state depends on the selected record, and update it from the controls' After Update events when users change their values.

Why does Command6 stay enabled after the condition becomes false?

Code that only sets Enabled = True leaves the previous state unchanged when the condition fails. In the form's VBA procedure, add an Else branch that sets Me!Command6.Enabled = False.

Can WPS Office run my Access form and fix this VBA error?

No. WPS Office is not an Access database or form runtime. Correct the VBA code in Microsoft Access; use WPS Spreadsheets for data exported from Access to an Excel-compatible file such as .xlsx.