A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Loop to process multiple selected files



 
 
Thread Tools Display Modes
  #1  
Old July 2nd, 2009, 12:16 AM posted to microsoft.public.access
Richard[_34_]
external usenet poster
 
Posts: 1
Default Loop to process multiple selected files

I have a module which imports text files into a database, but I need
to be able to select multiple files to be processed, this is what I
have so far


Public filename As String
Sub SelectFile()
Dim fd As FileDialog
Dim objfl As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = True
.Filters.Add "Text Files", "*.txt;*.txt", 1
.Title = "Choose your files"
.Show

For Each objfl In .SelectedItems
filename = objfl
Next objfl

If .SelectedItems.Count 0 Then
For i = 1 To .SelectedItems.Count
Call OpenText 'this is what imports the text
Next i
End If
End With
End Sub
I think I need to combine the For and If statements to make it work,
it will import the first file selected and if I choose two files it
will repeat the import of the first file selected. Any help is greatly
appreciated
Richard
  #2  
Old July 2nd, 2009, 08:55 PM posted to microsoft.public.access
Gary Brown[_5_]
external usenet poster
 
Posts: 87
Default Loop to process multiple selected files

You didn't show the 'OpenText' procedure BUT...
it looks like you need to tell the 'OpenText' procedure which file to process.

'- - - - - - - - - - - - -
For i = 1 To .SelectedItems.Count
Call OpenText( .SelectedItems(i))
Next i
'- - - - - - - - - - - - -
Sub OpenText(strFile as string)
'process strFile
End Sub
'- - - - - - - - - - - - -

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Richard" wrote:

I have a module which imports text files into a database, but I need
to be able to select multiple files to be processed, this is what I
have so far


Public filename As String
Sub SelectFile()
Dim fd As FileDialog
Dim objfl As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = True
.Filters.Add "Text Files", "*.txt;*.txt", 1
.Title = "Choose your files"
.Show

For Each objfl In .SelectedItems
filename = objfl
Next objfl

If .SelectedItems.Count 0 Then
For i = 1 To .SelectedItems.Count
Call OpenText 'this is what imports the text
Next i
End If
End With
End Sub
I think I need to combine the For and If statements to make it work,
it will import the first file selected and if I choose two files it
will repeat the import of the first file selected. Any help is greatly
appreciated
Richard

  #3  
Old July 4th, 2009, 05:30 AM posted to microsoft.public.access
Steve Sanford
external usenet poster
 
Posts: 190
Default Loop to process multiple selected files

I only have A2K, so I can't test this.

Looking at http://support.microsoft.com/kb/288543

I have modified you procedu
----Untested----
'-----------------------------------------------------
Option Compare Database
Option Explicit

Sub SelectFile()
Dim fd As FileDialog
Dim objfl As Variant

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Use a With...End With block to reference the FileDialog object.
'(Access XP and higher)
With fd

.ButtonName = "Select"
.AllowMultiSelect = True
.Filters.Add "Text Files", "*.txt;*.txt", 1
.Title = "Choose your files"
.Show

If .SelectedItems.Count 0 Then

'Step through the FileDialogSelectedItems collection.
For Each objfl In .SelectedItems
Call OpenText 'this is what imports the text
Next objfl

End If

End With

'Set the object variable to Nothing.
Set fd = Nothing

End Sub
'-----------------------------------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"Richard" wrote:

I have a module which imports text files into a database, but I need
to be able to select multiple files to be processed, this is what I
have so far


Public filename As String
Sub SelectFile()
Dim fd As FileDialog
Dim objfl As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = True
.Filters.Add "Text Files", "*.txt;*.txt", 1
.Title = "Choose your files"
.Show

For Each objfl In .SelectedItems
filename = objfl
Next objfl

If .SelectedItems.Count 0 Then
For i = 1 To .SelectedItems.Count
Call OpenText 'this is what imports the text
Next i
End If
End With
End Sub
I think I need to combine the For and If statements to make it work,
it will import the first file selected and if I choose two files it
will repeat the import of the first file selected. Any help is greatly
appreciated
Richard

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:47 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.