RowSourceType Property (User-Defined Function) - Code Argument Values

RowSourceType Property (User-Defined Function) — Code Argument Values

         Example

The Visual Basic function you create must accept five arguments. The first argument must be declared as a control and the remaining arguments as Variants. The function itself must return a Variant.

Syntax

Function functionname(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant

The Function procedure has the following five required arguments.

Argument Description
fld A control variable that refers to the list box or combo box being filled.
id A unique value that identifies the control being filled. This is useful when you want to use the same user-defined function for more than one list box or combo box and must distinguish between them. (The example sets this variable to the value of the Timer function.)
row The row being filled (zero-based).
col The column being filled (zero-based).
code An intrinsic constant that specifies the kind of information being requested.

Note   Because Microsoft Access calls a user-defined function several times to insert items into a list, often you must preserve information from call to call. The best way to do this is to use Static variables.

Microsoft Access calls the user-defined function by repeatedly using different values in the code argument to specify the information it needs. The code argument can use the following intrinsic constants.

Constant Meaning Function returns
acLBInitialize Initialize Nonzero if the function can fill the list; False (0) or Null otherwise.
acLBOpen Open Nonzero ID value if the function can fill the list; False or Null otherwise.
acLBGetRowCount Number of rows Number of rows in the list (can be zero); –1 if unknown.
acLBGetColumnCount Number of columns Number of columns in the list (can't be zero); must match the property sheet value.
acLBGetColumnWidth Column width Width (in twips) of the column specified by the col argument; –1 to use the default width.
acLBGetValue List entry List entry to be displayed in the row and column specified by the row and col arguments.
acLBGetFormat Format string Format string to be used to format the list entry displayed in the row and column specified by the row and col arguments; –1 to use the default format.
acLBEnd End (the last call to a user-defined function always uses this value) Nothing.
acLBClose (Not used) Not used.

Microsoft Access calls your user-defined function once for acLBInitialize, acLBOpen, acLBGetRowCount, and acLBGetColumnCount. It initializes the user-defined function, opens the query, and determines the number of rows and columns.

Microsoft Access calls your user-defined function twice for acLBGetColumnWidth — once to determine the total width of the list box or combo box and a second time to set the column width.

The number of times your user-defined function is called for acLBGetValue and acLBGetFormat to get list entries and to format strings varies depending on the number of entries, the user's scrolling, and other factors.

Microsoft Access calls the user-defined function for acLBEnd when the form is closed or each time the list box or combo box is queried.

Whenever a particular value (such as the number of columns) is required, returning Null or any invalid value causes Microsoft Access to stop calling the user-defined function with that code.

Tip   You can use the Select Case code structure from the example as a template for your own RowSourceType property user-defined functions.