Not IsNull (1 Viewer)

kitty77

Registered User.
Local time
Today, 06:55
Joined
May 27, 2019
Messages
693
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.
Local time
Today, 10:55
Joined
Apr 13, 2012
Messages
643
Have you tried adding an or eg :TextField IS NULL OR TextField=""

Just an idea

Ypma
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:55
Joined
Sep 21, 2011
Messages
14,050
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

MVP / VIP
Local time
Today, 10:55
Joined
Jan 14, 2017
Messages
18,186
If Nz(TestField,””)=“”) Then MsgBox “123”


Sent from my iPhone using Tapatalk
 

Dreamweaver

Well-known member
Local time
Today, 10:55
Joined
Nov 28, 2005
Messages
2,466
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.
Local time
Today, 21:55
Joined
Jul 4, 2013
Messages
2,770
@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
 

Dreamweaver

Well-known member
Local time
Today, 10:55
Joined
Nov 28, 2005
Messages
2,466
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

Top Bottom