IIf syntax to select one field or another

D

Donnithorn

I'm trying to create a query for my library database that will return
[Organizations]![Abbrev] when [Authors]![AuthurNum] is null and otherwise
return [Authors]![FirstName] & " " & [Authors]![LastName]. I've tried every
combination with parentheses and commas and spaces, but I keep getting error
messages in the query grid; or when I go to the table view, I get #Error.
How can I fix this?

By:
IIf(IsNull[Books]![AuthorID],[Organizations]![Abbrev],[Authors]![FirstName] &
" " & [Authors]![LastName])
 
D

Douglas J Steele

Only the actual field needs to be in the IsNull function. To make it obvious
what's missing, I've put spaces around the parentheses I added.

IIf(IsNull ( [Books]![AuthorID] )
,[Organizations]![Abbrev],[Authors]![FirstName] & " " &
[Authors]![LastName])
 
B

Barry Gilbert

You're missing brackets around you IsNull function call. It should be:

IIf(IsNull([Books]![AuthorID]),[Organizations]![Abbrev],[Authors]![FirstName] &
" " & [Authors]![LastName])

HTH,
Barry
 
Top