In
JohnE said:
I have a form and on it are various controls. One of the controls is
a combobox that needs to populate with word documents found in a
specified folder. I am stumped on how to make this work so I seek
assistance from the newsgroup. If anyone knows how to do this or
knows of an example I can review, that would be great.
I've done this using a custom list-filling function for the combo/list
box. Such a function must conform to a specific format, which is
documented in the help file (but unfortunately, it's very hard to find
the topic in all versions since Access 97). Here's an example of such a
function that gets the folder path and file pattern (e.g., "*.doc") from
controls on the form:
'------ start of code ------
Function FillFileList( _
fld As Control, _
ID As Variant, _
row As Variant, _
col As Variant, _
Code As Variant) _
As Variant
Static avarFiles(1000) As Variant
Static intEntries As Integer
Dim ReturnVal As Variant
ReturnVal = Null
Select Case Code
Case acLBInitialize ' Initialize.
intEntries = 0
avarFiles(intEntries) = _
Dir(Me.txtFolder & "\" & Nz(Me.txtPattern, "*.doc"))
Do Until avarFiles(intEntries) = vbNullString _
Or intEntries >= 1000
intEntries = intEntries + 1
avarFiles(intEntries) = Dir
Loop
If intEntries > 1 Then
QSArray avarFiles, LBound(avarFiles), intEntries - 1
End If
ReturnVal = intEntries
Case acLBOpen ' Open.
' Generate unique ID for control.
ReturnVal = Timer
Case acLBGetRowCount ' Get number of rows.
ReturnVal = intEntries
Case acLBGetColumnCount ' Get number of columns.
ReturnVal = 1
Case acLBGetColumnWidth ' Column width.
' -1 forces use of default width.
ReturnVal = -1
Case acLBGetValue ' Get data.
ReturnVal = avarFiles(row)
Case acLBEnd ' End.
Erase avarFiles
End Select
FillFileList = ReturnVal
End Function
'------ end of code ------
Note that this example maxes out at 1000 files.
To use this function, paste it into your form's module, and modify the
references to Me.txtFolder and Me.txtPattern in the code so as to pick
up the folder path and pattern from wherever you prefer. Then set the
combo box's RowSourceType property to
FillFileList
Leave the RowSource property blank.