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

Browsing for Files with FileDialog 1

Status
Not open for further replies.

inuman

Programmer
Feb 23, 2006
20
RO
Hi!

I had to work with some files and make a function to browse for those files, select them and process them through code.
I've read a lot of posts and solutions, but none of them worked for my Access XP database.
So I tried to find a solution myself and here is the one that worked for me:

***************************************************
Const msoFileDialogOpen = 1

Dim dlgOpen As Variant, itm As Variant
Dim strFileName As String

Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

With dlgOpen
.Title = "Import files "
.AllowMultiSelect = True
.ButtonName = "Import"
.Filters.CLEAR
.Filters.Add "File Type", "*.txt", 1
.InitialFileName = "C:\"

If .Show = -1 Then
Set objFile = CreateObject("Scripting.FileSystemObject")
For Each itm In .SelectedItems
strFileName = itm 'this is the filename
Set objtext = objFile.OpenTextFile(strFileName)
Next
End If
End With
************************************************

The solution with comdlg32.dll worked for me, but it didn't allow me to select more than 6 files at a time. If I selected 7 it returned me an empty String. Anyway with this String you have to split it in parts and do some more processing to obtain the filenames.

A nice day to all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top