简体   繁体   English

MS Access:基于多个表自动填充表单字段

[英]MS Access: Auto-populate form fields based on multiple tables

I have the following 3 tables: 我有以下3表:
Retailers - ID, Name 零售商-ID,名称
Registration - ID, Status (YES/NO) 注册-ID,状态(是/否)
Refund - ID (populated into a dropdown list from Retailers table), Name (Empty), Status (Empty) 退款-ID(从“零售商”表填充到下拉列表中),名称(空),状态(空)

Retailers is a table full of data, while Refund starts off as an empty table that gets filled in as a Refund Form is filled up. 零售商是一个充满数据的表,而退款是从一个空表开始的,该表会在填写退款表格时填写。 After creating a form based on the Refund table, how do I allow a user to select an ID from the dropdown list and populate the corresponding Name into the Name field and Status into the Status field? 根据退款表创建表单后,如何允许用户从下拉列表中选择ID,并将相应的“名称”填充到“名称”字段中,并将“状态”填充到“状态”字段中?

What are the queries needed and how do I integrate this into the form? 需要什么查询?如何将其集成到表单中?

I have tried the method found here - https://www.linkedin.com/pulse/autofill-form-microsoft-access-tim-miles 我已经尝试过在这里找到的方法-https: //www.linkedin.com/pulse/autofill-form-microsoft-access-tim-miles

However, I have run into 2 problems: 但是,我遇到了两个问题:

1) The form does not appear in "Form View"; 1)表单未出现在“表单视图”中; it is only viewable in layout view. 仅在布局视图中可见。 I have read many links saying that the queries are read-only or that there are no records in the first place etc. The answers don't make sense. 我已经阅读了许多链接,其中说查询是只读的,或者首先没有记录,等等。答案没有任何意义。

2) If I bind the form (instead of a table) to a query this way, how do I save this new data into another table? 2)如果我以这种方式将表单(而不是表)绑定到查询,如何将新数据保存到另一个表中? My intention was to have the record saved in Refund table. 我的意图是将记录保存在退款表中。

Sounds like Refund is your base table here. 听起来退款是您的基本表。 So, the query you want is: 因此,您想要的查询是:

SELECT a.[ID], b.[Name], c.[Status]
FROM Refund as a
Left Join Retailers as b
ON a.[ID] = b.[ID}
Left Join Registration as c
ON a.[ID] = c.[ID]

You'll need to make all 3 ID fields the Primary Keys in their respective tables. 您需要将所有3个ID字段设为各自表中的主键。 This should make the query updateable, and then you can use this query as the DatSource for your form. 这将使查询可更新,然后您可以将该查询用作表单的DatSource。

You also have to make sure you set up the Relationships for all the tables. 您还必须确保为所有表设置了“关系”。 If you've never done it, it's easy to do and Microsoft gives you instructions here: 如果您从未做到过,那很容易做到,Microsoft在这里为您提供说明:

https://support.office.com/en-us/article/Create-a-relationship-40c998dd-4875-4da4-98c8-8ac8f109b85b https://support.office.com/en-us/article/Create-a-relationship-40c998dd-4875-4da4-98c8-8ac8f109b85b

By setting up referential integrity in the relationships, you can save the data. 通过在关系中设置参照完整性,可以保存数据。

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

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