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?
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.
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.
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.
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.
If mrf
is Variant, then it's initially Empty
, not Null
. You therefore have to use IsEmpty()
function.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With