ms-accessiif-function

IIf clause in Access doesn't work correctly


I'm trying to create a table for invoice in Access and this is my table schema:

id AutoNumber
customer_name Number
product_name Number
count Number
unit Calculated
date Number

The customer name and product name are lookup wizard that select their data from another table. I need the unit automatically select the unit based on product name for example:

"ورق آ۴"

for these unit must fill itself with:

"برگ"

and for these:

"مداد"

must fill itself with:

"عدد"

so I write an expression for this:

IIf([product_name]="برگ","ورق آ۴",IIf([product_name]="عدد","مداد","-"))

but it fills all of the product units with "-". Any solution?


Solution

  • I try so many solutions but at last I decided to use product_id and work with it it's so simple and Access doesn't need to encode the text in IIf and compare any more!