Link to home
Start Free TrialLog in
Avatar of Hiro 714
Hiro 714

asked on

MS Access Question: how to use function to locate Blank record

I would like to use following function to locate Blank record
Blank: IIf(InStr([table],"")<>0,"Blank")
However it locates all not null record as "Blank"
Please advise.
Avatar of Daniel Pineault
Daniel Pineault

What constitutes a blank record?  A record where all the fields are NULL?  You could easily create a query for this, no?

I think you will need to explain your table structure and data more in detail.

Also, why not setup your table structure so you don't have blank records?
Avatar of Hiro 714

ASKER

Thank you, Daniel.
Blank record means Null and "" record.
Table has a field in short text, contains Null and ""
I want to create a query if the record is Null or "", then return "Blank" string
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If Len(YourField) =0

Open in new window

should cover your cases
I would suggest

Blank: IIf(Nz([YourFieldName],"") = "","Blank", Null)

rather than

Blank: IIf(Nz([YourFieldName]) = "","Blank", Null)

Because Nz() works differently in VBA than it does in SQL as well as differentiating between string and non-string data types.   I'm assuming that your field is a text data type otherwise it makes no sense at all to return "blank".

In this particular case, assuming you are working with a text data type, omitting the substitution value and allowing it to default will end up OK but most people have never read the help entry for Nz() and don't understand that the default may not be what they expect in certain situations so I recommend always specifying what result you want returned.  Rely on defaults at your own peril.  The really scary part of this particular default is that the function works differently in VBA than in SQL.  By always providing the result value, I avoid having to remember to consider the  what environment the expression will be evaluated by and does that impact the result I expect.