Module

  • Thread starter Thread starter Mareo
  • Start date Start date
M

Mareo

I have two fields in a record in access 2002. I want to
calculate the value in Field2 with a different constant
based on what is in Field1.

Field 1 Field 2
PCBs 2.3
Pesticides 10.5
Zinc 400
PCBs 3.2
Zinc 330
etc etc
. .
. .


If Field1 is Pcbs then I want to calc Field2 as
2.3/constant1
If Field1 is Pesticide then I want to calc Field2 as
10.5/constant2
If field1 is Zinc then I to calc Field2 as 400/constant3

How do I write a module to perform this task?

I have tried the switch funtion but get a syntax problem.
Field 2: Switch ([Field1] = "Pcbs", [Field2]/constant1,
[Field1]= "Pesticides", [Field2]/constant2, [Field1]
= "Zinc", [Field2]/constant3, True, Null)
 
Mareo said:
I have two fields in a record in access 2002. I want to
calculate the value in Field2 with a different constant
based on what is in Field1.

Field 1 Field 2
PCBs 2.3
Pesticides 10.5
Zinc 400
PCBs 3.2
Zinc 330
etc etc
. .
. .


If Field1 is Pcbs then I want to calc Field2 as
2.3/constant1
If Field1 is Pesticide then I want to calc Field2 as
10.5/constant2
If field1 is Zinc then I to calc Field2 as 400/constant3

How do I write a module to perform this task?

I have tried the switch funtion but get a syntax problem.
Field 2: Switch ([Field1] = "Pcbs", [Field2]/constant1,
[Field1]= "Pesticides", [Field2]/constant2, [Field1]
= "Zinc", [Field2]/constant3, True, Null)


Putting numbers like that in code (or anywhere in your
application) is a very poor practice. I strongly suggest
that you add those constants to a table. Then you could do
all this in a query by Joining the your existing table to
the constants table.

If you need help doing that, please post back with a
description of your existing table and its fields.
 
Back
Top