Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Not IsNull

Working with some VBA code in Access that when a very specific set of conditions are met it will pop up an InputBox asking for a integer. So far so good.

Private Sub Command10_Click()

    If Not IsNull(mrf) Then
        If min <> max Then
            If qty <= min Then
                mrf = GetParamValue
            End If
        End If
    End If
    End Sub

The problem is that the Not IsNull seems to be ignored. I would like it to ask for a value to be entered unless a value is already present. This keeps firing off the InputBox as long as the min <> max and qty <= min conditions are met. What am I missing here?

like image 339
Terry Avatar asked Mar 31 '09 19:03

Terry


People also ask

IS NOT null function in VBA?

ISNULL in VBA is a logical function used to determine whether a given reference is empty or NULL. That is why the name ISNULL is an inbuilt function that gives us True or False as a result. Based on the result, we can arrive at conclusions. For example, if the reference is empty, it returns a True or False value.

Does != Work in VBA?

How Not Equal Works in Excel VBA? VBA Not Equal works exactly opposite to the logic of equal to operator. Equal to operator returns TRUE if the supplied test is satisfied is not, it will return FALSE. So, for example, if you say 10 = 10, it will return TRUE or else FALSE.

Is null in VBA Access?

Returns a Boolean value that indicates whether an expression contains no valid data (Null). The required expressionargument is a Variant containing a numeric expression or string expression. IsNull returns True if expression is Null; otherwise, IsNull returns False.

What is not null access expression?

The IS [NOT] NULL predicate contains the following arguments. Any valid expression. Specifies that the Boolean result be negated. The predicate reverses its return values, returning TRUE if the value is not NULL, and FALSE if the value is NULL.


3 Answers

If mrf is Variant, then it's initially Empty, not Null. You therefore have to use IsEmpty() function.

like image 117
GSerg Avatar answered Nov 15 '22 04:11

GSerg


No, the Not IsNull is working perfectly.

Remember, IsNull is a function which returns TRUE if the parameter passed to it is null, and false otherwise.

Your "If Not IsNull(mrf) Then" statement translates into english as "If mrf is not null then"

what that means is when mrf has a value, then you're processing the code inside the if statement. If you're wanting the inner code to fire when mrf IS null, then you need to remove the NOT from the statement.

like image 32
Stephen Wrighton Avatar answered Nov 15 '22 04:11

Stephen Wrighton


My guess is that mrf isn't null, even if it's empty or something else. It could also be Nothing, which is different from null in VBA land (I think). Try running the code in the debugger and looking at the value of mrf. Depending on what mrf is, you can do a different test (like check len(mrf) or not isNothing(mrf) or if it's an integer, and it's init to zero, then mrf <> 0.... you get the idea. Hope that helps!

like image 41
Dan Coates Avatar answered Nov 15 '22 04:11

Dan Coates