RowSourceType, RowSource Properties

Applies To

Chart Control, Combo Box Control, List Box Control, Unbound Object Frame Control.

Description

You can use the RowSourceType and RowSource properties together to tell Microsoft Access how to provide data to a list box, a combo box, or an unbound OLE object such as a chart. For example, to display rows of data in a list box from a query named CustomerList, set the list box’s RowSourceType property to Table/Query and its RowSource property to the query named CustomerList.

Setting

The RowSourceType property has the following settings.

Setting

Description

Table/Query

(Default) The data is from a table, query, or SQL statement specified by the RowSource setting.

Value List

The data is a list of items specified by the RowSource setting.

Field List

The data is a list of field names from a table, query, or SQL statement specified by the RowSource setting.


Note You can also set the RowSourceType property with a user-defined function. In this case the data is an array of values defined by the user. The function name is entered without a preceding equal sign (=) and without the trailing pair of parentheses. You must provide specific function code arguments to tell Microsoft Access how to fill the control.

The RowSource property setting depends on the RowSourceType property setting.

For this RowSourceType

this RowSource

Table/Query

Enter a table name, a query name, or an SQL statement.

Value List

Enter a list of items using semicolons (;) as separators.

Field List

Enter a table name, a query name, or an SQL statement.


Note If the RowSourceType property is set to a user-defined function, the RowSource property must be left blank.

You can set the RowSourceType and RowSource properties using the control’s property sheet, a macro, or Visual Basic.

For table fields, you can set these properties in table Design view for fields with the DisplayControl property set to combo box or list box.

Note Microsoft Access sets these properties automatically when you select Lookup Wizard as the data type for a field in table Design view.

In Visual Basic, set the RowSourceType property using a string expression with one of these values: "Table/Query", "Value List", or "Field List". You also use a string expression to set the value of the RowSource property. To set the RowSourceType property to a user-defined function, enter the name of the function.

Remarks

When you have a limited number of values that do not change, you can set the RowSourceType property to Value List and then enter the values that make up the list in the RowSource property.

When you create a user-defined function to insert items into a list box or combo box, Microsoft Access calls the function repeatedly to get the information it needs. User-defined RowSourceType functions must be written in a very specific function format.

See Also

BoundColumn Property, ColumnWidths Property, ControlSource Property, RecordSource Property, RowSourceType (User-Defined Function) — Code Argument Values.

Example Settings

The following examples show sample RowSource property settings for each RowSourceType property setting.

When RowSourceType is set to Value List

If the RowSourceType property is set to Value List, the following table shows valid settings for the RowSource and ColumnCount properties and an illustration of the resulting list.

RowSource setting

List

Mon;Tue;Wed

(ColumnCount = 1)

One-column list with three rows


RowSource setting

List

1;Monday;2;Tuesday;3;Wednesday;4;Thursday

(ColumnCount = 2)

Two-column list with four rows

Country;Capital;China;Beijing;Brazil;Brasilia

(ColumnCount = 2, ColumnHeads = Yes)

Two-column list with one row of column heads and two rows of data


When RowSourceType is set to Table/Query

If the RowSourceType property is set to Table/Query, you can set the RowSource property to a table or query name — for example, CategoryList.

The following is a valid SQL statement for a two-column list drawn from the Categories table.


SELECT [CategoryID], [CategoryName] FROM [Categories] BY [CategoryName];

If the CategoryList query and the SQL statement define the same set of records, the list for either property setting looks like the following illustration.

When RowSourceType is set to Field List

If the RowSourceType property is set to Field List and the RowSource property to CustomerList (the query described in the previous example), the resulting list looks like the following illustration.

When RowSourceType is set to User-Defined

If the RowSourceType property is set to the name of a user-defined function, then the RowSource property setting must be left blank. For example, a user-defined function named ListMDBs that fills a combo box with the names of all the databases in the current directory is entered in the property sheet like the following illustration.

Example

The following example sets the RowSourceType property for a combo box to Table/Query, and it sets the RowSource property to a query named EmployeeList.


Forms![frmEmployees]![cmboNames].RowSourceType = "Table/Query"![frmEmployees]![cmboNames].RowSource = "EmployeeList"