How to: Use lookup columns
Show the name of a related record instead of its ID, or a symbol with text instead of a status number, and let users pick the value from a list.
Requires WKL Forms Object Library 1.23 or later.
Solution overview
Editor = wedLookup with RowSource (a table, query, SQL statement, or value list), BoundColumn,
and DisplayColumn works like an Access combo box. Editor = wedImageLookup with AddImageItem
maps stored values to an icon and text.
Implementation
With Me!List1.Object
With .Columns.Add("WarehouseID", "Warehouse")
.Editor = wedLookup
.RowSource = "SELECT WarehouseID, WarehouseName FROM tblWarehouses ORDER BY WarehouseName"
.BoundColumn = 1 ' stored value: WarehouseID
.DisplayColumn = 2 ' shown: WarehouseName
End With
With .Columns.Add("Priority", "Priority")
.Editor = wedLookup
.RowSource = "'low';'normal';'high'" ' value list
End With
With .Columns.Add("Status", "Status")
.Editor = wedImageLookup
.AddImageItem 0, "Info", "open"
.AddImageItem 1, "Settings", "in progress"
.AddImageItem 2, "Shield", "done"
End With
End With
Debug.Print Me!List1.Object.CellValue(7, "WarehouseID"), Me!List1.Object.CellText(7, "WarehouseID")
Remarks
CellValuereturns the stored value, andCellTextreturns the displayed text.- The Excel export writes the displayed text;
RawValues:=Truewrites the stored values. - Icon names are the same as for
ImageField: images from the database's image gallery, built-in names, or file paths. DisplayColumn = 0shows the bound column itself.
Related topics
en/wiki/msaccess/comctl/how-to/use-lookup-columns.txt · Last modified: by Wolfgang van der Stille