Calculated field with value from another table in Microsoft Access

Ponzaro

I have a calculated field in a table that needs to take the value from another table but in the expression generator window it doesn't allow me to choose values from other tables. Then, I tried to create a form from the table, and put in the source control the function that I need but it triggers a #Name? Error in the form.

This is the code that I put in the source control (Iff function) :

=IIf([Stato]="Vendita";[Costo ivato 1 pezzo]+(([Costo ivato 1 pezzo]/100)*[Provv_Vendita]![Costo]);[Costo ivato 1 pezzo]+(([Costo ivato 1 pezzo]/100)*[Provv_Prevendita]![Costo]))

[Stato] and [Costo ivato 1 pezzo] are two fields that are in the same table (called Prodotti) that is structured like this:

Stato      Costo Ivato 1 pezzo

Vendita         10
Prevendita      20

The other table (called Provvigioni) is like

Tipo        Costo

Vendita       1,5
Prevendita    5

Provv_Vendita and Provv_Prevendita are two queries that select the values that I need and are structured like this

SELECT Provvigioni.Costo
FROM Provvigioni
WHERE Provvigioni.Tipo="Vendita";

Is there a way to take the field from the other table and use in a function on the first table?

Matt Hall

I'm not 100% sure what you're after here, but I thought it would be best to show you how to link your 2 tables in a query first..

Go to Create > Query Design:

enter image description here

Add both your tables (double-click them):

enter image description here

Then close the Show Table window; you should have your tables in the Query Designer now:

enter image description here

Click and drag from Stato to Tipo; this should create a join between these fields:

enter image description here

Double-click on all your fields in each table so that they will appear in the query:

enter image description here

In the next available field for your query, right-click in the "Field" box and select "Zoom":

enter image description here

Put your IIF statement in there; precede it with a field name and colon, like this for example:

enter image description here

...Note that I've tidied your IFF statement up a bit, so it now reads:

MyCalculatedField: IIf([Stato]="Vendita",[Costo ivato 1 pezzo]+(([Costo ivato 1 pezzo]/100)*[Costo]),[Costo ivato 1 pezzo]+(([Costo ivato 1 pezzo]/100)*[Costo]))

Click OK on the "Zoom" window. Click "Run" to see the result of your query:

enter image description here

Here's what the query results in (check your calculated field is what you expect it to be):

enter image description here

If you want the result of this query to populate data in a form then you should save the query...

enter image description here

...and name it something:

enter image description here

You can then go to Create > Form Design:

enter image description here

In the Property Sheet on the right-hand side, go to the "Data" tab and use the drop-down next to Record Source to select the query you just saved:

enter image description here

If you go to Design > Add Existing Fields, you should be able to bring in the fields from your Query for use in your Form (Double-click or drag them to make appear on your Form):

enter image description here

Hope this helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculated field with value from another table in Microsoft Access

From Dev

MS Access-Using value from a form in a calculated field of a table

From Dev

Insert Calculated Field into Access Table

From Dev

Add one hour to Access table field, and save the value in another field

From Dev

Access SQL query that uses a field from one table within where clause to create a calculated field

From Dev

Access SQL query that uses a field from one table within where clause to create a calculated field

From Dev

Set field to random value from another table

From Dev

Microsoft Access Form - Auto Populate Form Field From Another Form

From Dev

How to access a row on a table based on a value from another table?

From Dev

Access Calculated Field

From Dev

Rails access calculated field

From Dev

cross table and calculated field

From Dev

Default value in calculated field

From Dev

MySQL Update - Set value in Table A with a value calculated from Table B

From Dev

Create a field that can store values calculated from values in another file

From Dev

Get data from a table based on a table name as a field value from another table

From Dev

select field from table in another field from another table

From Dev

SQL Select - Calculated Column if Value Exists in another Table

From Dev

How to display value of a field from a different table by using the value of a different column in another table

From Java

SQL/MS Access: Adding a automatically updating field in SQL table with sum of values from another table

From Dev

Update Microsoft Access Table Field from Excel App Via VBA/SQL

From Dev

how to set one field in a table equal to another field in a table in access

From Dev

Filemaker Getting Record ID from Related Value in Calculated Repeating Field

From Dev

MS ACCESS - Dynamically retrieve records from table based on criteria from another field

From Dev

Access 2010 Calculated Field - Table Requires More Space Than Static Field

From Dev

Access 2010 Calculated Field - Table Requires More Space Than Static Field

From Dev

Gravityforms field value from another field

From Dev

Access 2013 - Set a field value based on value of another field

From Dev

Union field Table from a Table in Access

Related Related

  1. 1

    Calculated field with value from another table in Microsoft Access

  2. 2

    MS Access-Using value from a form in a calculated field of a table

  3. 3

    Insert Calculated Field into Access Table

  4. 4

    Add one hour to Access table field, and save the value in another field

  5. 5

    Access SQL query that uses a field from one table within where clause to create a calculated field

  6. 6

    Access SQL query that uses a field from one table within where clause to create a calculated field

  7. 7

    Set field to random value from another table

  8. 8

    Microsoft Access Form - Auto Populate Form Field From Another Form

  9. 9

    How to access a row on a table based on a value from another table?

  10. 10

    Access Calculated Field

  11. 11

    Rails access calculated field

  12. 12

    cross table and calculated field

  13. 13

    Default value in calculated field

  14. 14

    MySQL Update - Set value in Table A with a value calculated from Table B

  15. 15

    Create a field that can store values calculated from values in another file

  16. 16

    Get data from a table based on a table name as a field value from another table

  17. 17

    select field from table in another field from another table

  18. 18

    SQL Select - Calculated Column if Value Exists in another Table

  19. 19

    How to display value of a field from a different table by using the value of a different column in another table

  20. 20

    SQL/MS Access: Adding a automatically updating field in SQL table with sum of values from another table

  21. 21

    Update Microsoft Access Table Field from Excel App Via VBA/SQL

  22. 22

    how to set one field in a table equal to another field in a table in access

  23. 23

    Filemaker Getting Record ID from Related Value in Calculated Repeating Field

  24. 24

    MS ACCESS - Dynamically retrieve records from table based on criteria from another field

  25. 25

    Access 2010 Calculated Field - Table Requires More Space Than Static Field

  26. 26

    Access 2010 Calculated Field - Table Requires More Space Than Static Field

  27. 27

    Gravityforms field value from another field

  28. 28

    Access 2013 - Set a field value based on value of another field

  29. 29

    Union field Table from a Table in Access

HotTag

Archive