That didn't work either, here are all the functions that I am using to populate the listbox with files, please help me get it working, or is there another way of doing so - thanks
---Code---
Function ListFiles(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
Static dbs(6000) As String
Static Entries As Integer
Dim ReturnVal As Variant
Dim strFolderName As String
Dim strTemp As String
ReturnVal = Null
Select Case code
Case acLBInitialize ' Initialize.
If Len(Nz(txtSelFolder)) = 0 Then
Entries = 0
Else
Entries = 0
'Build the directory name
If Right$(txtSelFolder, 1) = "\" Then
strFolderName = txtSelFolder & "*.*"
Else
strFolderName = txtSelFolder & "\" & "*.*"
End If
'
' If you use dynamic arrays
' find the total number of entries in the listbox
' Redim code to define dimensions of the array
' Before adding elements to the array
'
strTemp = Dir(strFolderName)
While strTemp <> ""
Entries = Entries + 1
dbs(Entries) = strTemp
strTemp = Dir
Wend
End If
ReturnVal = Entries
Case acLBOpen ' Open.
ReturnVal = Timer ' Generate unique ID for control.
Case acLBGetRowCount ' Get number of rows.
ReturnVal = Entries
Case acLBGetColumnCount ' Get number of columns.
ReturnVal = 1
Case acLBGetColumnWidth ' Column width.
ReturnVal = -1 ' -1 forces use of default width.
Case acLBGetValue ' Get data.
ReturnVal = dbs(row + 1)
Case acLBEnd ' End.
Erase dbs
End Select
ListFiles = ReturnVal
End Function
Private Function fnGetList(strType As String) As String
Dim objfs As Object, objFolder As Object
Dim objfiles As Object, objf1 As Object
Dim strfill As String
If Len(Nz(txtSelFolder)) = 0 Then
fnGetList = ""
Exit Function
End If
Set objfs = CreateObject("Scripting.FileSystemObject")
Set objFolder = objfs.GetFolder(txtSelFolder)
If strType = "Files" Then
Set objfiles = objFolder.Files
Else
Set objfiles = objFolder.Subfolders
End If
For Each objf1 In objfiles
strfill = strfill & objf1.name & ";"
Next
Set objf1 = Nothing
Set objfiles = Nothing
Set objFolder = Nothing
Set objfs = Nothing
fnGetList = strfill
End Function
Private Sub Form_Load()
Me.txtSelFolder.Value = CurrentProject.path & "\Reports"
Me.lstFile2.Requery
End Sub
---Code---