Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling a list box

Status
Not open for further replies.

Page410

Technical User
Mar 9, 2001
106
US
I have a form that fills a list box with file names from a directory but I need to be able to include the file created date as well. I don't know if my brain is cramping or this is actually difficult but I can't seem to think it through. Below is the code that I'm using to grab the file names (I've also included the public sub 'FillFiles'). The Dim dtedate is used to get the created date but now I need to figure out how to get it back to the fListFill function and finally to the list box. Any Ideas??

Any help would be greatly appreciated.

Thank you,
Mike

Function fListFill(ctl As Control, varID As Variant, lngRow As Long, _
lngCol As Long, intCode As Integer) As Variant

Static sastFiles() As String, slngCount As Long, sloclDir As clsDir
Dim i As Long, varRet As Variant, X As Long, strFileName As String

Select Case intCode
Case acLBInitialize
Set sloclDir = New clsDir
If Not mstFilePath = vbNullString Then
With sloclDir
.FillFiles mstFilePath
slngCount = .GetFileCount

If slngCount > 0 Then
ReDim sastFiles(0 To slngCount - 1)
For i = 1 To slngCount
strFileName = Left(.NameOfFile(i), Len(.NameOfFile(i)) - 4)
sastFiles(i - 1) = strFileName
Next i
PDF_accSortStringArray sastFiles()
End If
End With
Else
slngCount = 0
End If
varRet = True

Case acLBOpen
varRet = Timer

Case acLBGetRowCount
varRet = slngCount

Case acLBGetValue
If slngCount > 0 Then
varRet = sastFiles(lngRow)
Else
varRet = vbNullString
End If

Case acLBEnd
Set sloclDir = Nothing
Erase sastFiles
End Select
fListFill = varRet
End Function


Public Sub FillFiles(stDir As String)
Dim stName As String
Dim dtedate As Date
On Error GoTo err_FillFiles

'List all files in this folder
stName = Dir(stDir & "\*.*")
Do While stName <> &quot;&quot;
dtedate = fFileDate(stDir & stName)
On Error Resume Next
If (GetAttr(stDir & stName) And vbDirectory) <> vbDirectory Then
'File Already open?
If Err.Number = 5 Then Err.Clear

If stName <> &quot;.&quot; Or stName <> &quot;..&quot; Then
FileList.Add Item:=stName
FileList.stName.Tag = dtedate

End If
End If
'Get Next entry
stName = Dir
Loop

exit_FillFiles:
Exit Sub
err_FillFiles:
If Err.Number = 71 Then
MsgBox AccessError(Err.Number) _
& &quot; Please try again. &quot;, vbCritical + vbOKOnly, _
&quot;Error Reading Drive &quot; & stDir
End If
Resume exit_FillFiles
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top