We help IT Professionals succeed at work.

Why isn't this code working in MS Access 2010?

enviro-guy2010
on
I have created the following through the "Build" function in MS Access 2010 in Query design view under the "Field" cell.  It saves fine, but when I run the query, I get "#Error" as the query result.  I have read over the formula several times and I don't see a problem with it.  I tried double quotation marks and single quotation marks and both led to the same result.  Can anyone tell me what is wrong with the formula or offer suggestions on how to trouble shoot?  Thank you!

DESC: [Products]![FBPartNumber] & " " & IIf([Products]![Pieces]="N/A","",[Products]![Pieces] & " ") & IIf([LEDStyle]![LEDStyle]="N/A","",[LEDStyle]![LEDStyle] & " ") & IIf([Products]![LEDWattage]="N/A","",[Products]![LEDWattage] & "W ") & IIf([LensType]![LensType]="N/A","",[LensType]![LensType] & " ") & IIf([Products]![Voltage]="N/A","",[Products]![Voltage] & "V" & [Current]![Current] & " ") & IIf([Colors]![Color]="N/A","",[Colors]![Color] & " ") & IIf([Products]![KelvinTemp]="N/A","",[Products]![KelvinTemp] & "K ") & IIf([Products]![Lumens]="N/A","",[Products]![Lumens] & "LM")

DESC: [Products]![FBPartNumber] & ' ' & IIf([Products]![Pieces]='N/A','',[Products]![Pieces] & ' ') & IIf([LEDStyle]![LEDStyle]='N/A','',[LEDStyle]![LEDStyle] & ' ') & IIf([Products]![LEDWattage]='N/A','',[Products]![LEDWattage] & 'W ') & IIf([LensType]![LensType]='N/A','',[LensType]![LensType] & ' ') & IIf([Products]![Voltage]='N/A','',[Products]![Voltage] & 'V' & [Current]![Current] & ' ') & IIf([Colors]![Color]='N/A','',[Colors]![Color] & ' ') & IIf([Products]![KelvinTemp]='N/A','',[Products]![KelvinTemp] & 'K ') & IIf([Products]![Lumens]='N/A','',[Products]![Lumens] & 'LM')
Comment
Watch Question

Commented:
Do all of the fields you are using contain the same type of data?  Mixing data types in nested if statements can cause problems.
Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

Commented:
<<Can anyone tell me what is wrong with the formula or offer suggestions on how to trouble shoot?  Thank you!
>>

  Not sure where the error is, but I would put this in a custom function, then call the function from the query.  Heck of a lot easier to troubleshoot that way.

  Beyond that, why don't you have all this in a lookup table?

Jim.

Commented:
It looks like lookup tables are being used.  The formula is just creating a description string using the values that have been looked up.  The if statements are just saying if the value is N/A, then should nothing, else show the looked up value.

Would need to see the relationships of the tables in the queries, and some data in order to determin problem for sure.

Author

Commented:
That is exactly what the problem was.  Thanks for your help!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.