简体   繁体   中英

Create multiple records from a single record, with one field based on a second table

I'm completely new to creating MS Access databases, so please bear with me while I ask my (probably silly) question.

I have a table for commodities that also groups them into CropGroup and Class, and every commodity would also be considered 'Any food'.

Commodity table: 在此处输入图像描述

I would like to add one entry (maybe in a form?), with fields like 'Country' 'Commodity' 'Metal' 'Limit' with all fields identical other than the commodity. Rather than entering these manually for each commodity, is there a way that I can specify the country, metal and limit, select 'Fruit' or 'Anyfood' to automatically create a record for each commodity associated with these terms, so it looks similar to this? Doing this would save me hours if not days of work in the long term.

Output table:
在此处输入图像描述

Any suggestions or pointers in the right directions would be much appreciated!

Cheers, Sophie

You can set default value for text or comboboxes in data entry form. 在此处输入图像描述

So, you will set default value for each text box individually. When you you will run the form, text boxes will fill with default values automatically. If need you can then change values as per your need. As per my above screenshot, when you run the data entry form it will look like-

在此处输入图像描述

If anyone comes across to this question later, I was able to solve this perfectly with a relatively simple SQL query in the end:

INSERT INTO MetalLimits ( Country, Commodity, Element, [Limit(mg/kg)] )
SELECT Country, Commodity, Element, [Limit(mg/kg)]

FROM (SELECT Commodity FROM _CommodityList 
WHERE (([_CommodityList].CropGroup) Like [Enter CropGroup] & "*") AND 
(([_CommodityList].Class) Like [Enter Class] & "*")) ;

This allows manually entering Country, Element and Limit(mg/kg) as per the table rules (for MetalLimits table) in separate prompt pop-ups, and select the commodities based on the pre-defined CropGroup and Class (from _CommodityList) in another pop-up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM