Fix Null Values in an Access VBA SELECT DISTINCT Recordset
Question details
Determine why a SELECT DISTINCT query returns Null when its first field is read from an Access VBA recordset.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An Access VBA procedure reads distinct values from a table imported from an HTML-formatted file.
- Observed behavior
- The query works in the Access query designer, but the VBA recordset encounters a Null value in its first field. The imported table contains a mostly blank record with an ID.
Identify the imported table and the field being read from the recordset. Open the table in Access Datasheet View and check whether a record has an ID but no value in that field.
Filter Null and blank values from the DISTINCT query
Use this approach when records without a value in the selected field should not appear in the VBA results.
DISTINCT removes duplicate results; it does not exclude Null. A record with an assigned ID can still have a Null value in another field.
Open the imported table in Datasheet View and locate the field your VBA code reads. Confirm that records without a value in that field should be excluded.
In the SQL used by OpenRecordset, replace the example names with your own: SELECT DISTINCT [FieldName] FROM [WeeklyReport] WHERE [FieldName] Is Not Null AND [FieldName] <> '';
Run the VBA procedure again and check the returned values. Use an If Not rs.EOF check before reading rs.Fields(0), and call rs.MoveNext inside the loop.

Inspect and remove invalid imported records
Use this approach when the imported table should not retain mostly blank records.
Review Imported Data with WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for reviewing spreadsheet data. Its Microsoft Office format compatibility makes it easier to move existing files into your workflow, though it does not fix Access VBA or database imports.

Frequently Asked Questions
Why does SELECT DISTINCT return Null in Access?
DISTINCT removes duplicate values but can return Null when the selected field contains it. Add WHERE [FieldName] Is Not Null to exclude those results.
How can I exclude both Null and empty strings?
For a text field, add WHERE [FieldName] Is Not Null AND [FieldName] <> '' to the query. Use an additional Trim expression if whitespace-only values should also be excluded.
How do I check for Null in a VBA recordset?
Check that the recordset is not at EOF, then use IsNull(rs.Fields(0).Value) before processing the first field. This lets you handle Null without treating it as an ordinary string.
Why does an imported record have an ID but no other values?
An ID can be assigned even when other imported fields are blank. Inspect the imported table in Datasheet View and review the HTML source to determine which records are invalid.




