Access 2010 - display related record in a form

三世轮回 提交于 2019-12-25 04:07:33

问题


I have 2 related tables. Invoice (fields: number, buyer, supplier, etc.)
Company - all buyers and suppliers (fields: name,etc.)
Buyer ans supplier fields on invoice are referencing same field (company_id from company table)

On invoice form, I choose supplier ID from dropdown list and also buyer ID from dropdown list.
Task: To make the form little bit readable, I would like to automatically display a name of company after selecting company id in both fields.
What I did: I manually dragged the company name field to the form and wizard asked me which field I would like it to connect to (byuer or supplier), so I got 1 field working. How to create another field that shows company name? If I drag another instance of company name, wizard does not show so I can set it up and I can not find anywhere setting for that. Thank you for help.


回答1:


I think the best way is the following:

  1. Create a lookup query: Create a new query similar to this “SELECT CompanyId, CompanyName FROM t_Companies ORDER BY CompanyName;” and save it as “ql_Companies”

  2. Edit your Invoice table. For both your fields Buyer and Supplier do the following: Click on the field and select Lookup in the filed properties. Set the following properties: Change Display Control = Combo Box, Row Source = ql_Companies, Column Count = 2, Column Width = 0;5 and save the table.

  3. Now when you create a new form based on your Invoice table the field will be automatically shown as a combobox.

You can also do all this manually on an existing form but then the combo box will only show on this one form. If you prepare the underlying table with lookup queries then this will work in all queries and forms automatically without additional work.



来源:https://stackoverflow.com/questions/27755285/access-2010-display-related-record-in-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!