[英]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.