Link to home
Create AccountLog in
Avatar of enviro-guy2010
enviro-guy2010Flag for United States of America

asked on

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

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')
ASKER CERTIFIED SOLUTION
Avatar of upsfa
upsfa

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Jim Dettman (EE MVE)
<<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.
Avatar of upsfa
upsfa

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.
Avatar of enviro-guy2010

ASKER

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