Access Cookbook - Ken Getz [151]
Constant
Meaning
Return value
acLBInitialize
Initialize the data.
Nonzero if the function will be able to fill the list; Null or 0 otherwise
acLBOpen
Open the control.
Nonzero unique ID if the function will be able to fill the list; Null or 0 otherwise
acLBGetRowCount
Get the number of rows.
Number of rows in the list; -1 if unknown (see the text for information)
acLBGetColumnCount
Get the number of columns.
Number of columns in the list (cannot be 0)
acLBGetColumnWidth
Get the column widths.
Width (in twips) of the column specified in the lngCol argument (zero-based); specify -1 to use the default width
acLBGetValue
Get a value to display.
Value to be displayed in the row and column specified by the lngRow and lngCol arguments
acLBGetFormat
Get the column formats.
Format string to be used by the column specified in lngCol
acLBClose
Not used.
acLBEnd
End (when the form is closed).
Nothing
You'll find that almost all of your list-filling functions will be structured the same way. Therefore, you may find it useful to always start with the ListFillSkeleton function, which is set up to receive all the correct parameters and includes a Select Case statement to handle each of the useful values of intCode. All you need to do is change its name and make it return some real values. The ListFillSkeleton function is as follows:
Function ListFillSkeleton (ctl As Control, _
varId As Variant, lngRow As Long, lngCol As Long, _
intCode As Integer) As Variant
Dim varRetval As Variant
Select Case intCode
Case acLBInitialize
' Could you initialize?
varRetval = True
Case acLBOpen
' What's the unique identifier?
varRetval = Timer
Case acLBGetRowCount
' How many rows are there to be?
Case acLBGetColumnCount
' How many columns are there to be?
Case acLBGetValue
' What's the value in each row/column to be?
Case acLBGetColumnWidth
' How many twips wide should each column be?
' (optional)
Case acLBGetFormat
' What's the format for each column to be?
' (optional)
Case acLBEnd
' Just clean up, if necessary (optional, unless you use
' an array whose memory you want to release).
End Select
ListFillSkeleton = varRetval
End Function
For example, the following function from frmListFill, ListFill1, fills in the first list box on the form. This function fills in a two-column list box, with the second column hidden (its width is set to 0 twips). Each time Access calls the function with acLBGetValue in intCode, the function calculates a new value for the date and returns it as the return value. The source code for ListFill1 is:
Private Function ListFill1(ctl As Control, varId As Variant, _
lngRow As Long, lngCol As Long, intCode As Integer)
Select Case intCode
Case acLBInitialize
' Could you initialize?
ListFill1 = True
Case acLBOpen
' What's the unique identifier?
ListFill1 = Timer
Case acLBGetRowCount
' How many rows are there to be?
ListFill1 = 7
Case acLBGetColumnCount
' How many columns are there to be?
' The first column will hold the day of the week.
' The second, hidden column will hold the actual date.
ListFill1 = 2
Case acLBGetColumnWidth
' How many twips wide should each column be?
' Set the width of the second column to 0.
' Remember, they're zero-based.
If lngCol = 1 Then ListFill1 = 0
Case acLBGetFormat
' What's the format for each column to be?
' Set the format for the first column so
' that it displays the day of the week.
If lngCol = 0 Then
ListFill1 = "dddd"
Else
ListFill1 = "mm/dd/yy"
End If
Case acLBGetValue
' What's the value for each row in each column to be?
' No matter which column you're in, return
' the date lngRow days from now.
ListFill1 = Now + lngRow
Case acLBEnd
' Just clean up, if necessary.
End Select
End Function
The next example, which fills the second list box on the sample form, fills an array of values in the initialization step (acLBInitialize) and returns items from the array when requested.