Delete Access Records with Null Values Using VBA
Question details
Delete all Access table records where a specified field is Null when a form loads.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An Access form should run a deletion query automatically during its Load event.
- Observed behavior
- When the form loads, records with a Null value in the chosen field should be deleted.
Identify the table and field to check, and confirm that deleting the matching records is intended every time the form loads. Run a SELECT query with the same Is Null condition first to review which records will be affected.
Run a DELETE query in the Access form's Load event
Use the form's Load event to delete matching records whenever the form opens.
In the Navigation Pane, right-click the form and select Design View. Open the Property Sheet and select the form.
On the Property Sheet's Event tab, select On Load, choose [Event Procedure], and click the ellipsis button to open the VBA editor.
Inside the Form_Load procedure, enter: CurrentDb.Execute "DELETE FROM [tablename] WHERE [fieldname] Is Null;", dbFailOnError. Replace tablename and fieldname with the actual table and field names.
Save the form, open it in Form View, and inspect the table to verify that only the intended records were deleted.

Work with Office documents using WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for an easier migration. It does not run Access VBA or replace Access for managing its databases.

Frequently Asked Questions
How can I preview the records before deleting them?
In Access, create a query in SQL View and run SELECT * FROM [tablename] WHERE [fieldname] Is Null; after replacing the table and field names.
Does Is Null also find empty strings?
No. Is Null finds Null values, not zero-length strings. For a text field, use a condition such as [fieldname] Is Null OR [fieldname] = '' if both should be included.
Why does the delete query report an error?
Check the table and field names, deletion permissions, and any relationships that prevent deleting the records. The dbFailOnError option causes Access to report an error when the action query cannot complete.
Can WPS Office run the Access form's VBA code?
No. Run the form and its VBA Load event in Microsoft Access. You can export table data to an Excel-compatible file and open it in WPS Spreadsheets for review.




