简体   繁体   English

Microsoft Access 2010-外键作为下拉列表

[英]Microsoft Access 2010 - Foreign Key as Dropdown

I have two tables that I display in a form: 我有两个表格以表格形式显示:

tblUsers -> user_id, firstname, lastname, group_id tblUsers-> user_id,名字,姓氏,group_id

tblGroups -> group_id, groupName, groupDesc tblGroups-> group_id,groupName,groupDesc

I can get the data that I want with: 我可以获得所需的数据:

SELECT tblUsers.firstname, tblUsers.lastname, tblGroups.groupName FROM tblGroups INNER JOIN tblUsers ON tblGroups.[group_id] = tblUsers.[group_id]; 从tblGroups内部联接中选择tblUsers.firstname,tblUsers.lastname,tblGroups.groupName。tblGroups上的tblUsers。

But what I need is a form that shows the user information and a dropdown list for the group but showing the name of the group not the ID and so the group can be changed for a specific user eg Manager, Editor etc... 但是我需要的是一个表格,该表格显示用户信息和组的下拉列表,但显示组的名称而不是ID,因此可以为特定用户更改组,例如管理员,编辑器等。

Thanks, Gareth 谢谢加雷斯

Right-click on the ComboBox (assuming it's a ComboBox...) and open the Properties window. 右键单击ComboBox(假设它是ComboBox ...),然后打开“属性”窗口。

Set the Row Source to: 将行源设置为:

Select Group_ID, GroupName from tblGroups

Set the Column Count to 2, because you want the combo to store both the ID and the Group name 将列计数设置为2,因为您希望组合存储ID和组名称

Set the Column Widths to "0; 2" (without the quotes). 将列宽设置为“ 0; 2”(不带引号)。 This will essentially hide the ID because the column width of the ID field is 0. 这实际上将隐藏ID,因为ID字段的列宽为0。

Set the Bound Column to 1, because you want to bind to the ID column and not the Group Name column, because the Group ID is easier to query with. 将“绑定列”设置为1,因为您要绑定到ID列而不是“组名”列,因为要查询组ID更容易。

Then you reference the combo with Me!MyComboboxName.Value to get the Group ID. 然后,使用Me!MyComboboxName.Value引用组合以获取组ID。

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

相关问题 Microsoft Access在子窗体中填充外键 - microsoft access populate foreign key in subform Microsoft Access 2010在连续表单标题子表单中滞后 - Microsoft Access 2010 lag in continuous form header subforms 未选择下拉列表时,避免使用trigering外键约束 - Avoiding trigering foreign key constraint when dropdown is not selected 在MS-Access中,当外键不再存在时,如何在组合框中显示旧的外键? - In MS-Access, how to display the old foreign key in a combo box when the foreign key no longer exists? 在django中验证表单时如何访问外键? - How to access foreign key while validating form in django? SQL语句,用于将数据从条目表单中提取到Microsoft Access 2010 VBA中的数据表 - SQL Statement to grab data from entry form to Data table in Microsoft Access 2010 VBA 如何在Microsoft Access 2007/2010中创建从子表单到表单中特定记录的超链接 - How Create an Hyperlink from a sub form to a specific record in a form in Microsoft Access 2007/2010 如何创建包含所有外键属性值的activeadmin下拉菜单表单输入 - How to create activeadmin dropdown menu form input that contains all foreign key attribute values 带外键的Django表单 - Django Forms With foreign key 如何在Access表单上使外键组合框变得用户友好? - How do I make foreign-key combo boxes user-friendly on an Access form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM