Not IsNull (1 Viewer)

kitty77

Registered User
Joined
May 27, 2019
Messages
161
I'm working with the following...
If Not IsNull([test]) Then MsgBox "testing 123"

It does not seem to be working. Some records that are blank or empty or null show the MsgBox.

How can I make it check for blank, empty and null?

It seems like some value must be there even though you can't see anything...

Thanks.
 

ypma

Registered User
Joined
Apr 13, 2012
Messages
567
Have you tried adding an or eg :TextField IS NULL OR TextField=""

Just an idea

Ypma
 

Gasman

Enthusiastic Amateur
Joined
Sep 21, 2011
Messages
5,017
I'm working with the following...
If Not IsNull([test]) Then MsgBox "testing 123"

It does not seem to be working. Some records that are blank or empty or null show the MsgBox.

How can I make it check for blank, empty and null?

It seems like some value must be there even though you can't see anything...

Thanks.
Blank ot empty is not Null?
You could have a zero length string ZLS ""
 

isladogs

CID Moderator
Staff member
Joined
Jan 14, 2017
Messages
12,365
If Nz(TestField,””)=“”) Then MsgBox “123”


Sent from my iPhone using Tapatalk
 

MickJav

AWF VIP
Joined
Nov 28, 2005
Messages
1,278
I can't take credit for this as found it on the web so many years ago I forgot when but use it all the time.


Code:
Function IsNothing(varToTest As Variant) As Boolean
'Function found on web
On Error GoTo HandleErr

    IsNothing = True

    Select Case VarType(varToTest)
        Case vbEmpty
            Exit Function
        Case vbNull
            Exit Function
        Case vbBoolean
            If varToTest Then IsNothing = False
        Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
            If varToTest <> 0 Then IsNothing = False
        Case vbDate
            IsNothing = False
        Case vbString
            If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing = False
    End Select
    
HandleExit:
    Exit Function
    
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox Err.Number & vbCrLf & Err.Description
            Resume HandleExit
        Resume
    End Select
 

Cronk

Registered User
Joined
Jul 4, 2013
Messages
2,238
@MickJav


That function has a problem handing boolean variables because of the line
Code:
If varToTest Then IsNothing = False
If the passed variable is False, then the function gives the variable as missing.


Note that in #4

Code:
If Nz(TestField,””)=“”)
will be true for both a null and a ZLS
 

MickJav

AWF VIP
Joined
Nov 28, 2005
Messages
1,278
It's always worked but I don't use it to test boolean I alway give mine a default of false
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom