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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Scrape into a Listbox???

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
MX
Hi everyone:
I have a form with a listbox and would like to file scrape everything is a specific directory folder and populate it in a listbox. Can I do this and How?
Thanks
Zishan
 
Try this....

First, create a table called tblFileNames.
make sure to include the following fields in your table:
Filename (as text)
DateModified (as date)
FileSize (as number)

Next, include the following code in the On Load event of the form that contains your list box.

Private Sub Form_Load()

Dim strPath As String
Dim strFile As String

On Error GoTo errorhandler

strPath = "C:\YourLocation\"
strFile = Dir(strPath & "*.*")

While strFile <> &quot;&quot;
CurrentDb.Execute &quot;INSERT INTO tblFileNames
(Filename,DateModified,FileSize) VALUES('&quot; & strFile
& &quot;',#&quot; & Format(FileDateTime(strPath &
strFile), &quot;mm/dd/yyyy&quot;) & &quot;#,&quot; & FileLen(strPath &
strFile) & &quot;)&quot;
strFile = Dir()
Wend

errorhandler:

Err.Clear

End sub

Finally, on your form, within the Row Source of the list box, build your query to view the fields from tblFileNames.

I hope this helps you.
 
i found something like this in a ms help file and, with a little adaptation, it worked great:

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Function varFunctionListFiles(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant)

' Returns the names of the text files in specified directory, called by lstFileSelect on sbdImport:

Static strEntry(127) As String
Static intEntries As Integer
Static strFilePath As String

strFilePath = strPath & &quot;*.txt&quot;

Dim varReturnValue As Variant
varReturnValue = Null

Select Case code

Case acLBInitialize ' initialize.

intEntries = 0

strEntry(intEntries) = Dir(strFilePath)

Do Until strEntry(intEntries) = &quot;&quot; Or intEntries = 127

intEntries = intEntries + 1
strEntry(intEntries) = Dir

Loop

varReturnValue = intEntries

Case acLBOpen ' open (timer generates unique id for control)
varReturnValue = Timer

Case acLBGetRowCount ' get number of rows ( # of rows = # of entries)
varReturnValue = intEntries

Case acLBGetColumnCount ' get number of columns ( # of columns = 1)
varReturnValue = 1

Case acLBGetColumnWidth ' column width ( -1 forces default width)
varReturnValue = -1

Case acLBGetValue ' get data
varReturnValue = strEntry(row)

Case acLBEnd ' end

Erase strEntry ' clear 'strEntry' and free memory

End Select

varFunctionListFiles = varReturnValue

End Function

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
oh, by the way, you'll need to put the name of the function in the &quot;rowsource&quot; property of the listbox you're trying to fill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top