I am trying to concatenate the contents of the following fields:
[FirstNames]
[Prefix]
[LastName]
Company names are used in the LastName field.
There should be only one space between the first two and the last two fields.
I have the following expression in a query field:
CombiName: IIf([FirstNames] Is Null,[LastName],IIf([Prefix] Is Not Null,[ FirstNames] & " " & [Prefix] & " " & [LastName],[Firstnames] & " " & [LastName]))
When running the query the expression works correctly except in some of the cases where the FirstName and LastName appear. Sometimes there is just one space (which is correct and to be expected) between the FirstNames and LastName but sometimes there are, to me inexplicably, two spaces.
I cannot find a pattern in this, it seems to me that 2 spaces are randomnly attached.
I tried using the TRIM function just in case the fields have any additional spaces:
CombiName: IIf([Firstnames] Is Null,[LastName],IIf([Prefix] Is Not Null,[Firstnames] & " " & [Prefix] & " " & [LastName],TRIM([Firstnames]) & " " & TRIM([LastName])))
But that did not resolve the problem.
Am I overlooking something or is there something wrong with the expression?