Skip to content
Auscultby NBIT
EN
Free diagnostic

Access error reference

Access error 94: “Invalid use of Null” in VBA, causes and fix

A button works as long as everything is filled in, then stops on “Invalid use of Null” as soon as a control is left empty. The VBA code received Null, the value of an empty control or field, where it expected text, a number or a date.

The message

Microsoft Visual Basic box: “Run-time error '94': Invalid use of Null”
The real error box, captured in Access for Microsoft 365, in English: a Null value (a DLookup that finds nothing) is stored in a String variable.

Invalid use of Null

English Access, VBA run-time error box (error 94)

On a French Access: « Utilisation incorrecte de Null ». The message names nothing: the line highlighted in yellow in the VBA editor, after clicking “Debug”, tells you where.

Where it shows up

In the code of a button, a form event or a function: strName = Me.txtName, lngId = DLookup(…), CLng(Me.cboCustomer), rs!EndDate put into a Date variable, or a value passed to a function that does not accept Null.

Common causes

  • a text box or combo box left empty: its value is Null, and a String, Long, Date or Boolean variable cannot hold it;
  • an empty field in the table (rs!Phone, Me!LeaveDate) read into a typed variable;
  • a DLookup, DMax or DFirst that finds nothing: it returns Null, not zero or an empty string;
  • a conversion: CStr, CLng, CDate or CInt on a Null value also raise error 94.

How to reproduce and check it

  1. Note the form and the button, then try again leaving each control the code reads empty.
  2. Click “Debug”: the yellow line shows the variable receiving the value.
  3. In the Immediate window (Ctrl+G), type ? IsNull(Me.txtName) or ? IsNull(DLookup("Id", "Customers", "Code='A1'")) to see the Null value.

How to fix it

First decide what an empty control means: refuse the action, or use a default value. To refuse, test before use: If IsNull(Me.cboCustomer) Then MsgBox "Choose a customer.": Exit Sub.

For a default value, Nz replaces Null: strName = Nz(Me.txtName, ""), lngId = Nz(DLookup("CustomerID", "Customers", "Code='A1'"), 0). A Variant variable accepts Null, but only pushes the problem further down the code.

What Auscult reports

The diagnostic tries the database's forms and buttons in Access, on a copy, and records error 94 with the form or button that raises it. The report explains it as “The code found an empty field where it expected a value” and suggests handling the case of a field left empty.

When the error only comes from a condition (a control not filled in, an empty table on the copy), the report files it as a conditional fault: “fails if …”, with the condition explained.

The Access error reference, code by code

Frequently asked questions

Why does error 94 only happen for some users?

Because it depends on the data: a control one user always fills in and another leaves empty, or an old record where a field was never entered.

Should I wrap everything in Nz?

No. Nz hides missing data behind a default value: keep it for cases where zero or an empty string make sense. When the value is required, refuse the action with a clear message.

Where are the other errors in your application hiding?

The diagnostic runs on your computer, on a copy of the application, without sending the data in your tables. The health grade and the summary are free.