Filling a ComboBox with a user-defined function

R

RobertS

I pulled the follwoing from A-97 help. I put "ListMondays"
into the RowSourceType property for a ComboBox. Do i need
to put arguments also? If so, how? Do I need an "=" sign?
Is there any help available for this feature?

The following user-defined function returns a list of the
next four Mondays following today's date. To call this
function from a list box control, enter ListMondays as the
RowSourceType property setting and leave the RowSource
property setting blank.

Function ListMondays(fld As Control,id As Variant,row As
Variant,col As Variant,code As Variant) As Variant
Dim intOffset As Integer
Select Case code
Case acLBInitialize
' Initialize.
ListMondays = True
Case acLBOpen 'Open.
ListMondays = Timer 'Unique ID.
Case acLBGetRowCount 'Get rows.
ListMondays = 4
Case acLBGetColumnCount 'Get columns.
ListMondays = 1
Case acLBGetColumnWidth 'Get col width.
ListMondays = -1 'Use default
width.
Case acLBGetValue 'Get the data.
intOffset = Abs((9 - Weekday(Now))
Mod 7)
ListMondays = Format(Now() + _
intOffset + 7 * row,"mmmm d")
End Select
End Function


Thanks!
 
A

Allen Browne

No. You do not include the equals sign, the function brackets, or the
arguments. The RowSourceType is just:
ListMondays

These callback functions are quite odd beasts. You better believe it when
the documentation says that you can't guarantee the order in which Access
will ask for items from the list. If the function needs to lookup
information, the best approach is generally to load a static array with the
desired values in the case acLBInitialize, and then grab the value from the
array in case acLBGetValue.

There's another basic example of reading files from a folder at:
http://allenbrowne.com/func-02.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top