-
1
- #1
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!
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!