Access: checking blank variables
Wednesday, September 9, 2009
I often have to test String, Variant or Object variables that have no content and could be considered ‘blank’.
The problem is that testing for “blankness” can mean many different things to different types:
- For an
Objecttype, the variable can beNothing. - For a
Stringtype, the string can have no content at all:"",vbNullString. - For a
Varianttype, the string can have any of the following attributes or values:- it can be
Missingif the variable is an unused optional parameter, - it can be
Emptyif it was never assigned, - it can be
Nullif, for instance it’s bound to a nullable field or unbound with no value, - it can be an empty string
"",vbNullString.
- it can be
When having to check these variables in code, it can be tiresome to have to go through testing some of these possibilities just to find out that your variable does or not not contains something useful, regardless of the type of variable you are using.
To avoid having to do all these tests, make the code a bit more tidy and allow me to move on to more important things, I use this small utility function quite often:
So now I don’t have to worry so much about the type of the variable I’m testing when I want to know if it contains useful data:
Obviously, IsBlank() doesn’t replace the other tests but I found it to be more straightforward to use in most cases.
Entry Filed under : Database,MSAccess,Programming

2 Comments Add your own
1. Patrick Honorez | February 17th, 2010 at 2:49 pm
For strings, it is apparently faster to test if LEN(strTest) > 0, since VBA stores strings starting with bytes containing the length of the string.
2. James Barker | April 25th, 2013 at 11:18 pm
I have always wanted to know this
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed