Your second iif needs to be one of the first iff's arguments; it can't stand alone like that.
An example of the names and what you expected as the outcome would have been helpful, but with assumptions of your expectations on my part, try this:
Surnames:IIf([surname2] = [surname1], [surname1], [surname1] & " and " & [surname2] & IIf(Not IsNull([surname3]), " and " & [surname3], ""))
Edit: simpler and more accurate:
Surnames: surname1 & IIf([surname2] = [surname1], "", " and " & surname2) & IIf(Not IsNull(surname3), " and " & surname3, "")
Edit: Third attempt, works better
Surnames: surname1 & IIf([surname2] = [surname1], "", IIf(IsNull(surname2), "", " and " & surname2) & IIf(Not IsNull(surname3), " and " & surname3, ""))
And here's a function that works and only took 5 minutes to write and debug (Don't you just hate those compound IIFs ?)
Code:
Public Function fcnSurnames(n1 As String, n2 As String, n3 As String)
Dim rslt As String
rslt = n1
Select Case (n2 & "") = ""
Case False
Select Case n1 = n2
Case False
rslt = rslt & " and " & n2
End Select
End Select
Select Case (n3 & "") = ""
Case False
rslt = rslt & " and " & n3
End Select
fcnSurnames = rslt
End Function
None of these account for Surname 1 being blank
OR surname1 = surname3
OR surname2 = surname3