Confused by "Null"

Hello~

It seems to me that the value NULL has some strange and inconsistent behavior in VBA. I would appreciate if anybody could help me out with the NULL - I guess there is something special about NULL that I haven't realized.

Here is a recent example:

The codes below is expected to calculate [TwoEstDate] according to the updated value in textbox [Text_OneReturnDate]: if it is null then the [TwoEstDate] is null, otherwise [TwoEstDate] is the 10th Monday after the [Text_OneReturnDate].

To debug, I added a watch for the value of [Text_OneReturnDate]. When I clear the contents in [Text_OneReturnDate], in the watch window, it shows Me!Text_OneReturnDate.Value is Null. So it should be line 1 that is executed. But what actually happened was, the code in line 1 is not executed, and line 2 was executed instead.



Private Sub Text_OneReturnDate_AfterUpdate()
If Me!Text_OneReturnDate.Value = Null Then
Me![TwoEstDate] = Null 'line 1
Else
Me![TwoEstDate] = XthMonday(Me![Text_OneReturnDate].Value, 10) 'line 2
End If
End Sub


Answer this question

Confused by "Null"

  • Vaish

    in vba in order to check for a null value you must use the IsNull Function

    If IsNull(Me!Text_OneReturnDate.Value ) then...



  • Modeller

    wow... thank you so much~

  • Confused by "Null"