Your question #1... if that expression is being used as
the control source of a control in your report then be
sure the names in brackets are bound control names, not
just the field names in the report's recordsource.
Your question #2... try this modified version. I changed
several things to address your issues, one being that your
function can now also return a null value. The key point
to understand is how each punctuation gets concantinated
with a value, as Wayne has already mentioned.
Public Function NFormat(chrFirst As Variant, _
chrMiddle As Variant, chrLast As Variant, _
chrSuffix As Variant, chrCompany As Variant, _
varStyle As Variant) As Variant
On Error GoTo Err_NFormat
Dim strNewName As Variant
Select Case varStyle
Case "0", "FML"
strNewName = chrFirst & (" " + chrMiddle) _
& (" " + chrLast) & (", " + chrSuffix)
Case "1", "LFM"
strNewName = chrLast & (", " + chrSuffix) _
& (", " + chrFirst) & (" " + chrMiddle)
Case "2", "LFMC"
strNewName = (chrLast & (", " + chrSuffix) _
& (", " + chrFirst) & (" " + chrMiddle) + " / ") _
& chrCompany
Case Else
strNewName = ""
End Select
NFormat = Trim(strNewName)
Exit Function
Err_NFormat:
NFormat = "#Error"
End Function
>-----Original Message-----
>Hi,
>
>I created a function to concatenate names using knowledge
>base article acc2000 Sample Function to Format Names
>Several Different Ways.
>
>I have 2 questions:
>1. I'm using the following in a report and it's not
>working. What am I doing wrong?
>
>=NFormat([chrFirst],[chrMiddle],[chrLast],[chrSuffix],
>[chrCompany],1)
>
>2. I have a few records that only have a company name
and
>no first and last name. When I run the function, I only
>want the company name to display and not a , or /.
>
>LFM displays: , (It should be blank)
>LFMC displays: / XYZ Company (It should be XYZ Company)
>
>*****
>
>Public Function NFormat(chrFirst As Variant, chrMiddle As
>Variant, chrLast As _
> Variant, chrSuffix As Variant, chrCompany As Variant,
>varStyle As Variant)
>
> On Error GoTo Err_NFormat
>
> Dim strNewName As String
>
> Select Case varStyle
> Case "0", "FML"
> strNewName = chrFirst & " " & (chrMiddle + " ")
&
>chrLast & (", " + chrSuffix)
> Case "1", "LFM"
> strNewName = chrLast & (", " + chrSuffix) &
(", "
>& chrFirst) & (" " + chrMiddle)
> Case "2", "LFMC"
> strNewName = chrLast & (", " + chrSuffix) &
(", "
>+ chrFirst) & (" " + chrMiddle) & (" / " + chrCompany)
> Case Else
> strNewName = ""
> End Select
>
> NFormat = Trim(strNewName)
> Exit Function
>
>Err_NFormat:
> NFormat = "#Error"
>End Function
>
>
>Thank you.
>
>jbc
>.
>
|