write a custome "if" function in access

hamid sajjadi

New Member
Joined
Jan 6, 2018
Messages
7
Office Version
  1. 2019
Platform
  1. MacOS
hello every body.
I've written a code in my excel.Now I want to write such formule in access too.how can i write this "if" statement in access?
Code:
=IF(AND(F11=8484,OR(G11=20,G11=21)),8470,IF(AND(F11=8484,OR(G11=40,G11=41)),8472,F11))

each cell in the above formule reffers to a field in my table (query).for example F11 reffers to "account code" and G11 reffers to sub account code.i want to put this code in a new calculated field in access.
thank u
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This should work.

Expr1: IIf([A]=8484 And (=20 Or =21),8470,IIf([A]=8484 And (=40 Or =41),8472,[A]))

The letters are the Field Names that you change to yours.

Best done in a Query instead of the Table.
 
Last edited:
Upvote 0
is it possible to use many "or" expression?indeed I need to have over 10 "or" expression.
another question.why y say "Best done in a Query instead of the Table.".what is the advantage?
 
Upvote 0
is it possible to use many "or" expression?indeed I need to have over 10 "or" expression.
Yes, you can do multiple AND or OR statements.

Best done in a Query instead of the Table.".what is the advantage?
While it is true that newer versions allow you to create and store some calculations right on table level now, it is usually best to keep doing them in a query instead, for a few reasons, including:
1. The table-level calculations are limited, in regards to what you can do.
2. No other database program allows this. So if your database ever needed to grow and you needed to migrate it to something bigger like SQL, it wouldn't work (not compatible if you do that).
3. It violates the rules of data normalization (which all well-designed databases should strive for) in which none of your table fields should be dependent on other table fields.
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top