MS Access: Display two columns in combo-box

喜夏-厌秋 提交于 2019-12-05 11:44:04

It depends to a certain extent on what you are doing, often something like this suits:

SELECT Id, Surname & ", " & Forename from Table

In other words, the bound column is a unique ID and the selection column includes both the surname and forename in a single column.

EDIT based on additional information:

SELECT [Contact].[CID], [Contact].[Csname] & ", " & [Contact].[Cfname] 
FROM [Contact] ORDER BY [CID], [Csname], [Cfname];

Since my first column is used to group items in the second it didn't look nice to just separate them using

SELECT ID, [Type] & ": " & [Title] AS BothValues

as suggested. With a lot of items the dropdown looks confusing like in this example.

I found out that Access seems to display the first (technically) visible column in the combobox after a selection has been made. Therefore I ended up using

SELECT ID, [Type] & ": " & [Title] AS BothValues, Type, Title

and setting the width of the second column to the smallest possible, de facto invisible value (0";0.007";1",1"). Don't forget to raise the column count (4). Now the dropdown appears grouped, but I still get both information after the selection.

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