Table of contents
TOC
Collapse the table of content
Expand the table of content

ListBox Object (Access)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

This object corresponds to a list box control. The list box control displays a list of values or alternatives.

Remarks

In many cases, it's quicker and easier to select a value from a list than to remember a value to type. A list of choices also helps ensure that the value that's entered in a field is correct.

Control:Tool:

List box control

| List box tool

|

Note The list in a list box consists of rows of data. Rows can have one or more columns, which can appear with or without headings.

Multi-column list box

If a multiple-column list box is bound, Microsoft Access stores the values from one of the columns.

You can use an unbound list box to store a value that you can use with another control. For example, you could use an unbound list box to limit the values in another list box or in a custom dialog box. You could also use an unbound list box to find a record based on the value you select in the list box.

If you don't have room on your form to display a list box, or if you want to be able to type new values as well as select values from a list, use a combo box instead of a list box.

Links provided by:Community Member Icon TheUtterAccess community

Example

This example demonstrates how to filter the contents of a list box while you are typing in a text box.

In this example, a list box named ColorID displays a list of colors stored in the Colors table. As you type in the FilterBy text box, the items in ColorID are filtered dynamically

To do this, use the Change event of the text box to build a SQL statement that will serve as the new RowSource of the list box.

Sample code provided by:Community Member Icon TheUtterAccess community

Private Sub FilterBy_Change()

    Dim sql As String

    'This will match any entry in the list that begins with what the user 
    'has typed in the FilterBy control
    sql = "SELECT ColorID, ColorName FROM Colors WHERE ColorName Like '" & Me.FilterBy.Text & "*' ORDER BY ColorName"

    'If you want to match any part of the string then add wildcard (*) before
    'the FilterBy.Text, too:
    'sql = "SELECT ColorID, ColorName FROM Colors WHERE ColorName Like '*" & Me.FilterBy.Text & "*' ORDER BY ColorName"

    Me.ColorID.RowSource = sql

End Sub

Events

Name
AfterUpdate
BeforeUpdate
Click
DblClick
Enter
Exit
GotFocus
KeyDown
KeyPress
KeyUp
LostFocus
MouseDown
MouseMove
MouseUp

Methods

Name
AddItem
Move
RemoveItem
Requery
SetFocus
SizeToFit
Undo

Properties

Name
AddColon
AfterUpdate
AllowValueListEdits
Application
AutoLabel
BackColor
BackShade
BackThemeColorIndex
BackTint
BeforeUpdate
BorderColor
BorderShade
BorderStyle
BorderThemeColorIndex
BorderTint
BorderWidth
BottomPadding
BoundColumn
Column
ColumnCount
ColumnHeads
ColumnHidden
ColumnOrder
ColumnWidth
ColumnWidths
Controls
ControlSource
ControlTipText
ControlType
DefaultValue
DisplayWhen
Enabled
EventProcPrefix
FontBold
FontItalic
FontName
FontSize
FontUnderline
FontWeight
ForeColor
ForeShade
ForeThemeColorIndex
ForeTint
GridlineColor
GridlineShade
GridlineStyleBottom
GridlineStyleLeft
GridlineStyleRight
GridlineStyleTop
GridlineThemeColorIndex
GridlineTint
GridlineWidthBottom
GridlineWidthLeft
GridlineWidthRight
GridlineWidthTop
Height
HelpContextId
HideDuplicates
HorizontalAnchor
Hyperlink
IMEHold
IMEMode
IMESentenceMode
InheritValueList
InSelection
IsVisible
ItemData
ItemsSelected
LabelAlign
LabelX
LabelY
Layout
LayoutID
Left
LeftPadding
ListCount
ListIndex
ListItemsEditForm
Locked
MultiSelect
Name
NumeralShapes
OldBorderStyle
OldValue
OnClick
OnDblClick
OnEnter
OnExit
OnGotFocus
OnKeyDown
OnKeyPress
OnKeyUp
OnLostFocus
OnMouseDown
OnMouseMove
OnMouseUp
Parent
Properties
ReadingOrder
Recordset
RightPadding
RowSource
RowSourceType
ScrollBarAlign
Section
Selected
ShortcutMenuBar
ShowOnlyRowSourceValues
SmartTags
SpecialEffect
StatusBarText
TabIndex
TabStop
Tag
ThemeFontIndex
Top
TopPadding
ValidationRule
ValidationText
Value
VerticalAnchor
Visible
Width

About the Contributors

UtterAccess is the premier Microsoft Access wiki and help forum. Click here to join.

See also

Concepts

Access Object Model Reference

© 2017 Microsoft