简体   繁体   English

如何使用不同表中数字字段的 SUM 更新数字字段 MS-ACCESS 13

[英]How to Update a numeric field with the SUM of the numeric field in a different table MS-ACCESS 13

I have a supply inventory database with 3 tables.我有一个包含 3 个表的供应库存数据库。 Main (Warehouse Stock), Supply Issue Table, and Supply Purchases Table.主要(仓库库存)、供应问题表和供应采购表。 All three tables share the relationship ITEM #.所有三个表共享关系 ITEM #。 Supply Issue and Supply Purchases both log transactions (ie Item #, Quantity Issued or purchased). Supply Issue 和 Supply Purchases 都记录交易(即项目编号、发出或购买的数量)。 I need to have the Purchase and Issue tables update the total quantity in the Main Table我需要让采购和发行表更新主表中的总数量

I created an update query to update the two fields in the main table(PQuantity/IQuantity).我创建了一个更新查询来更新主表(PQuantity/IQuantity)中的两个字段。 Then a third auto-calculated field (MQuantity) which is (PQuantity-IQuantity).然后是第三个自动计算字段 (MQuantity),即 (PQuantity-IQuantity)。 I did it this way because I understood I couldn't run an update query for an auto-calculated field?我这样做是因为我知道我无法对自动计算的字段运行更新查询?

Here's the update query SQL for purchases:这是购买的更新查询 SQL:

UPDATE [MAIN (WAREHOUSE STOCK)] 
INNER JOIN [Supply Purchases Table] 
ON [MAIN (WAREHOUSE STOCK)].[ITEM #] = [Supply Purchases Table].[ITEM #] 
SET [MAIN (WAREHOUSE STOCK)].PQUANTITY = +[Supply Purchases Table]![QTY  ADDED];

Here's the update query SQL for issues:这是问题的更新查询 SQL:

UPDATE [MAIN (WAREHOUSE STOCK)] 
INNER JOIN [Supply Issue Table] 
ON [MAIN (WAREHOUSE STOCK)].[ITEM #] = [Supply Issue Table].[ITEM #] 
SET [MAIN (WAREHOUSE STOCK)].IQUANTITY = +[Supply Issue Table]![QTY ISSUED];

The problem with this is it will only total the last purchase or issue that was input.这样做的问题是它只会总计输入的最后一次购买或问题。 I also get "Type conversion" errors.我也收到“类型转换”错误。

Am I making this too difficult?我让这太难了吗?

Thanks!谢谢!

You have to add QTY ADDED to the old value of PQUANTITY like:您必须将QTY ADDEDPQUANTITY的旧值中,例如:

UPDATE
    [MAIN (WAREHOUSE STOCK)]
    INNER JOIN
        [Supply Purchases TABLE]
    ON
        [MAIN (WAREHOUSE STOCK)].[ITEM #]  = [Supply Purchases TABLE].[ITEM #]
    SET [MAIN (WAREHOUSE STOCK)].PQUANTITY = [MAIN (WAREHOUSE STOCK)].PQUANTITY + [Supply Purchases TABLE]![QTY ADDED];

But you should rethink you data structure, as usuallay you have only one table for transactions (IN/OUT) and compute the actual stock when needed.但是你应该重新考虑你的数据结构,像往常一样,你只有一张交易表(进/出),并在需要时计算实际库存。 See Ms Featured Access Templates Inventory and Allen Browne AppInventory for some hints.有关一些提示,请参阅Ms Featured Access Templates InventoryAllen Browne AppInventory

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用MS Access 2016在VBA表达式中编写数字字段? - How to write a numeric field in a VBA expression using MS Access 2016? ms-access:更新记录,其中某些字段=文本框值 - ms-access: update record where some field = textbox value 如何更改表的字段ms-access 2013 VBA中存储的小数位数? - How to change number of decimal places stored in a table's field ms-access 2013 VBA? 查询不会更新子表单 MS-Access 中的表 - Query will not update table in subform MS-Access MS Access VBA 更新组合框表字段 - MS Access VBA to update a Combobox table field 如何将没有表单字段的值以及其余表单字段作为新记录ms-access 2013发送到表? - How to send a value which does not have a form field, along with the rest of the form fields to a table as a new record ms-access 2013? 我们如何通过仅使用代码生成器从 ms-access 中的表源更新特定字段来填充其他表单字段 - How can we populate other form fields by updating a specific field from table sources in ms-access using code builder only 如何在表单的不同字段中将数字日期转换为带有月份名称的字符日期? (使用权) - How can I convert a numeric date into a character date with the month name in a different field in a form? (Access) 用NULL更新带有表单中文本字段的数值字段 - Update with NULL for a Numeric field with a textfield in a form MS-Access列表框链接到YES / NO类型字段的问题 - Troubles with an MS-Access Listbox linked to a YES/NO type field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM