简体   繁体   中英

Microsoft Access 2010 - Foreign Key as Dropdown

I have two tables that I display in a form:

tblUsers -> user_id, firstname, lastname, group_id

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];

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...

Thanks, Gareth

Right-click on the ComboBox (assuming it's a ComboBox...) and open the Properties window.

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

Set the Column Widths to "0; 2" (without the quotes). This will essentially hide the ID because the column width of the ID field is 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.

Then you reference the combo with Me!MyComboboxName.Value to get the Group ID.

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