View Single Post
  #9  
Old June 4th, 2010, 06:52 PM posted to microsoft.public.access.reports
David W. Fenton
external usenet poster
 
Posts: 3,373
Default Firstname plus Middlename??

John Spencer wrote in
:

You should be using the & concatenate operator instead of the +
operator.

The plus returns blank if any of the values are null (blank/never
entered).

The & operator treats nulls as if they were a zero-length string
("") and so has no problem if any of the fields are blank - other
than you may get some unwanted spaces.


Put another way, the + operator used with strings propagates Nulls.
That is actually quite useful, and I capitalize on it all the time.
For example:

Mid(("12"+LastName) & (", "+FirstName), 3)

That will produce correct results when neither field is Null, when
both are Null, and when either is Null and the other is not. It's
much more efficient and easy to read than the nested IIf() tests
that would otherwise be required.

Beware, though, that if a field has a string in it that is coercable
to a numeric value, you may end up with addition instead of
concatenation. For instance, "12"+LastName could produce a numeric
100012 if, for instance, the LastName field contained the string
"100000". This implicit type coercion is often quite helpful, but in
this case, it wouldn't be.

Note that it won't happen in *all* cases -- that very
unpredictability is the reason why you have to be careful with it.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/