Help New here would like to know how to do an if Command

A

Anton

Hii guys this is my first post here , first of all Thank you for reading this
message and even more is you can help me with this issue .

I am trying to do a querue from various tables and need to include a
computed field which will work like the if command in Excel ie
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

can some tell me if this is possible and if yes how i should type it ?

Thanking you all

Anton Cini
 
F

fredg

Hii guys this is my first post here , first of all Thank you for reading this
message and even more is you can help me with this issue .

I am trying to do a querue from various tables and need to include a
computed field which will work like the if command in Excel ie
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

can some tell me if this is possible and if yes how i should type it ?

Thanking you all

Anton Cini

Well you've done pretty well.
In Access you would use IIf()
In a query?
NewColumn:IIf (field XX > 0, field XX * Field YY,Field XX * Field ZZ)

Look up IIf in VBA help.

You do know, I hope, that in Access you do not save calculated data in
a table. Any time you need this calculated data re-calculate it.
 
W

Wayne-I-M

Hi Anton

In your example
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

Ensure that you have the table containing the fields in the query and create
a calculated column (right click and select build). You would need to write
something like this.

Result:IIf ( [TableName]![FieldXX] >0, [TableName]![FieldXX] *
[TableName]![FieldYY] , [TableName]![FieldXX] * [TableName]![FieldZZ] )

Of course change the TableName and field Names to what they really are.

_________________________________________

In an access query you can create calculated columns that will perform
calcuations if certain criteria are true and if they are not tru perform
different calculations.

Like this
Result:IIF([TableName1]![FieldName1]>0,[TableName2]![FieldName2]*[TableName3]![FieldName3],[TableName2]![FieldName2]*123)

The above calculation would ask
If the field called FieldName1 in a table called TableName1 is more than 0
then multiply the contents of the field called FieldName2 in TableName2 by
FieldName2 in TableName3. If the is NOT true then muliply FieldName2 in
TableName2 by 123 (one hundred and twenty three).

The basics are that with an IIF you ask is something true or is it not. If
it is you do "something" and if it's not then do "something" else. Hope this
make sense.


Hope this helps
 
A

Anton

Hii Fred/Wajne

Thank you for your help , i am using the formula i will pastit below so you
can check it please the problem is it is not working correctly for the first
record .

I will give it some trying myself as i dont want to be a pest , then i will
come back here.

Thank you all
--
Access For Fun


Wayne-I-M said:
Hi Anton

In your examp
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

Ensure that you have the table containing the fields in the query and create
a calculated column (right click and select build). You would need to write
something like this.

Result:IIf ( [TableName]![FieldXX] >0, [TableName]![FieldXX] *
[TableName]![FieldYY] , [TableName]![FieldXX] * [TableName]![FieldZZ] )

Of course change the TableName and field Names to what they really are.

_________________________________________

In an access query you can create calculated columns that will perform
calcuations if certain criteria are true and if they are not tru perform
different calculations.

Like this
Result:IIF([TableName1]![FieldName1]>0,[TableName2]![FieldName2]*[TableName3]![FieldName3],[TableName2]![FieldName2]*123)

The above calculation would ask
If the field called FieldName1 in a table called TableName1 is more than 0
then multiply the contents of the field called FieldName2 in TableName2 by
FieldName2 in TableName3. If the is NOT true then muliply FieldName2 in
TableName2 by 123 (one hundred and twenty three).

The basics are that with an IIF you ask is something true or is it not. If
it is you do "something" and if it's not then do "something" else. Hope this
make sense.


Hope this helps



--
Wayne
Manchester, England.



Anton said:
Hii guys this is my first post here , first of all Thank you for reading this
message and even more is you can help me with this issue .

I am trying to do a querue from various tables and need to include a
computed field which will work like the if command in Excel ie
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

can some tell me if this is possible and if yes how i should type it ?

Thanking you all

Anton Cini
 
A

Anton

Wahhoooo.

did it it is working fine i have it done thank you guys ,, will be look ing
often here.

I small think where do i find the VBA help ?
thank you
Access for Fun
--
Access For Fun


Anton said:
Hii Fred/Wajne

Thank you for your help , i am using the formula i will pastit below so you
can check it please the problem is it is not working correctly for the first
record .

I will give it some trying myself as i dont want to be a pest , then i will
come back here.

Thank you all
--
Access For Fun


Wayne-I-M said:
Hi Anton

In your examp
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

Ensure that you have the table containing the fields in the query and create
a calculated column (right click and select build). You would need to write
something like this.

Result:IIf ( [TableName]![FieldXX] >0, [TableName]![FieldXX] *
[TableName]![FieldYY] , [TableName]![FieldXX] * [TableName]![FieldZZ] )

Of course change the TableName and field Names to what they really are.

_________________________________________

In an access query you can create calculated columns that will perform
calcuations if certain criteria are true and if they are not tru perform
different calculations.

Like this
Result:IIF([TableName1]![FieldName1]>0,[TableName2]![FieldName2]*[TableName3]![FieldName3],[TableName2]![FieldName2]*123)

The above calculation would ask
If the field called FieldName1 in a table called TableName1 is more than 0
then multiply the contents of the field called FieldName2 in TableName2 by
FieldName2 in TableName3. If the is NOT true then muliply FieldName2 in
TableName2 by 123 (one hundred and twenty three).

The basics are that with an IIF you ask is something true or is it not. If
it is you do "something" and if it's not then do "something" else. Hope this
make sense.


Hope this helps



--
Wayne
Manchester, England.



Anton said:
Hii guys this is my first post here , first of all Thank you for reading this
message and even more is you can help me with this issue .

I am trying to do a querue from various tables and need to include a
computed field which will work like the if command in Excel ie
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

can some tell me if this is possible and if yes how i should type it ?

Thanking you all

Anton Cini
 
W

Wayne-I-M

Hi Anton

I am pleased it worked for you.

You can get help on VBA by pressing F1 in access and puttng the question in
the box. Or, if you have a specific problem you can post it in this forum
and I am sure that you will get an answer to most problems. You can also
search here

http://groups.google.com/advanced_search?q=&

put this
microsoft.public.access
in the box "Return only messages from the group at this location"
then type a few key words into the top box


Good luck with your project

--
Wayne
Manchester, England.



Anton said:
Wahhoooo.

did it it is working fine i have it done thank you guys ,, will be look ing
often here.

I small think where do i find the VBA help ?
thank you
Access for Fun
--
Access For Fun


Anton said:
Hii Fred/Wajne

Thank you for your help , i am using the formula i will pastit below so you
can check it please the problem is it is not working correctly for the first
record .

I will give it some trying myself as i dont want to be a pest , then i will
come back here.

Thank you all
--
Access For Fun


Wayne-I-M said:
Hi Anton

In your examp
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

Ensure that you have the table containing the fields in the query and create
a calculated column (right click and select build). You would need to write
something like this.

Result:IIf ( [TableName]![FieldXX] >0, [TableName]![FieldXX] *
[TableName]![FieldYY] , [TableName]![FieldXX] * [TableName]![FieldZZ] )

Of course change the TableName and field Names to what they really are.

_________________________________________

In an access query you can create calculated columns that will perform
calcuations if certain criteria are true and if they are not tru perform
different calculations.

Like this
Result:IIF([TableName1]![FieldName1]>0,[TableName2]![FieldName2]*[TableName3]![FieldName3],[TableName2]![FieldName2]*123)

The above calculation would ask
If the field called FieldName1 in a table called TableName1 is more than 0
then multiply the contents of the field called FieldName2 in TableName2 by
FieldName2 in TableName3. If the is NOT true then muliply FieldName2 in
TableName2 by 123 (one hundred and twenty three).

The basics are that with an IIF you ask is something true or is it not. If
it is you do "something" and if it's not then do "something" else. Hope this
make sense.


Hope this helps



--
Wayne
Manchester, England.



:

Hii guys this is my first post here , first of all Thank you for reading this
message and even more is you can help me with this issue .

I am trying to do a querue from various tables and need to include a
computed field which will work like the if command in Excel ie
= if ( field XX > 0, field XX * Field YY,Field XX * Field ZZ)

can some tell me if this is possible and if yes how i should type it ?

Thanking you all

Anton Cini
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top