In trying to learn VBA, and studying examples of code, I see both the
"+" and the "&" use to concatenate strings seemingly interchangeably
(at least to a novice, such as myself). What exactly are the rules,
implications, consequences, etc. of using one or the other?
The & should be your default choice. The main difference is that + propagates
Nulls whereas & does not.
"Some Text" & Null resolves to... "Some Text"
"Some Text" + Null resolves to... Null
In most cases the first result is what is desired, but there are some cases
where the second is desired and that is when you would choose the plus sign.
For example, you might be concatenating several lines of a address into a single
TextBox with line-feeds...
Address Line 1
Address Line 2
City, ST ZipCode
....would be produced by using...
[Address1] & vbCrLf & _
[Address2] & vbCrLf & _
[City] & ", " & [State] & " " & [ZipCode]
If some records do not have an Address2 entry then the above expression would
still leave a blank line. However; I don't get the blank line if I use...
[Address1] & vbCrLf & _
([Address2] + vbCrLf) & _
[City] & ", " & [State] & " " & [ZipCode]
The other issue with + is that if you use it to concatenate two string fields
that contain digits you might end up with addition being performed instead of
concatenation. The & operator would never do that.