I am trying to create a string for a SQL statement in code that gives the same results as the following built in a standard Access query:
SELECT tblContributor.ContributorKey, [tblContributor]![LastName] & IIf(IsNull([tblContributor]![Suffix]),"",(", " & [tblContributor]![Suffix])) & ", " & IIf(IsNull([tblContributor]![Prefix]),"",([tblContributor]![Prefix] & " ") & [tblContributor]![FirstName] AS Name, tblContributor.LastName
FROM tblContributor
ORDER BY [tblContributor]![LastName] & IIf(IsNull([tblContributor]![Suffix]),"",(", " & [tblContributor]![Suffix])) & ", " & IIf(IsNull([tblContributor]![Prefix]),"",([tblContributor]![Prefix] & " ") & [tblContributor]![FirstName];
When I paste this query into code to be used as the basis for a combo box row source, I get a compile error “Expected end of statement” with the first comma in the first IIf statement ((", " ) highlighted.
Can I use a statement like this to set the row source in code? What changes are needed to do that?
Thanks.
SELECT tblContributor.ContributorKey, [tblContributor]![LastName] & IIf(IsNull([tblContributor]![Suffix]),"",(", " & [tblContributor]![Suffix])) & ", " & IIf(IsNull([tblContributor]![Prefix]),"",([tblContributor]![Prefix] & " ") & [tblContributor]![FirstName] AS Name, tblContributor.LastName
FROM tblContributor
ORDER BY [tblContributor]![LastName] & IIf(IsNull([tblContributor]![Suffix]),"",(", " & [tblContributor]![Suffix])) & ", " & IIf(IsNull([tblContributor]![Prefix]),"",([tblContributor]![Prefix] & " ") & [tblContributor]![FirstName];
When I paste this query into code to be used as the basis for a combo box row source, I get a compile error “Expected end of statement” with the first comma in the first IIf statement ((", " ) highlighted.
Can I use a statement like this to set the row source in code? What changes are needed to do that?
Thanks.