Null Values

  • Thread starter Thread starter David Tunstall
  • Start date Start date
D

David Tunstall

Please help.

I have this code but am unsure of where it should go:
(On Form open, Form requery.........)

Function ErrorAvoid(n As Variant) As Variant
On Error GoTo Trap
ErrorAvoid = n
Exit Function
Trap:
ErrorAvoid = 0
Resume Next
Exit Function
End Function


Hope this makes sense
Thanks
David
 
Beats us....what's it supposed to do? I'd put in a regular module and then
call it from some other event's code, I guess.
 
Oh....OK.

That code (posted by Arvin Meyer, who is a very respected MVP in ACCESS for
many years, and a great guy!) is a precursor of a function that now is built
into VBA -- namely, the Nz function.

The Nz function can be called at any time to replace a null value in an
expression or a variable with another value of your choosing.

For example, suppose a numeric variable named VarIsMyName might contain a
Null value, and if it does, it should be considered to be the number zero.
If I were using this VarIsMyName in a calculation (where Null would wipe out
the results), I'd use the Nz function this way:

MyAnswer = 12 * Nz(VarIsMyName, 0)

Thus, if VarIsMyName, the Nz function replaces the Null with zero.

You can use any value you want in place of the Null. The next example shows
the use of the number 11:

MyAnswer = 12 * Nz(VarIsMyName, 11)

If StrIsMyName is a text-formatted field and I want to replace a Null value
with the text string "UseMeInstead", I'd do this:

MsgBox "This is the value: " & Nz([StrIsMyName], "UseMeInstead")
 
Back
Top