Forum Discussion
Jalessa
Aug 07, 2025Iron Contributor
What's the cleanest way to skip NULLs when looping through Recordest in VBA?
I've been working on a legacy Access app, and I find myself looping through a DAO recordest to process a bunch of fields. The thing is , some of those fields occasionally contain NULLs, and I've noti...
HillenL
Aug 21, 2025Iron Contributor
In VBA the cleanest way is to wrap your field access with Nz() (Access) or a helper function, so you don’t have to sprinkle IsNull everywhere
Dim val As String
val = Nz(rs!MyField, "") ' returns "" instead of Null
or for numbers
val = Nz(rs!Amount, 0)
If you want to skip nulls entirely, a simple patterns is
If Not IsNull(rs!MyField) Then
' process it
End If
But in practise, using Nz() or a customer safeVal() function keeps the code much cleaner when looping over multiple fields.