The following function creates a display name from a [last name] and
[her name] and [his name]. I call the function from a query. When I
run the query those records that have BOTH a his and her name appear
correctly, but if one of the names is blank "#ERROR" appears in the
field where the combined name should appear. Why doesn't the function
process the else statement correctly? The If statement works just
fine.
Thank you in advance.
- jc -
This is how it is called from the query:
name:cname([his_name], [her_name])
The function: (resides in a module)
Public Function cName(strHisName As String, strHerName As String) As
String
On Error GoTo Err_cName
If (Len(Trim(Nz(strHisName))) > 0) And (Len(Trim(Nz(strHerName))) >
0) Then
cName = Trim(strHisName) & " & " & Trim(strHerName)
Else
cName = Trim(Nz(strHisName)) & Trim(Nz(strHerName))
End If
Exit_cName:
Exit Function
Err_cName:
cName = ""
MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf &
Err.Description
Resume Exit_cName
End Function