Loop through FileListBox

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Loop through FileListBox

Post by D Willett »

Hi.
I'm using a FileListBox to "Filecopy" from a multi select process.
The following code is only copying one file across and not the multiple items as selected.
strDest doesn't change...
Something probably very simple, but I can't see it?

Code: Select all

If Me.TreeView1.SelectedItem.Text = "" Then
MsgBox "No Vehicle Selected", vbInformation, ""
Exit Sub
End If

If Me.File1 = "" Then
MsgBox "No Method Selected", vbInformation, ""
Exit Sub
End If

    Dim N As String
    Dim strDest As String
    Dim i As Integer
    
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
        strDest = "L:\mmpdf\ConsoleFiles\" & txtEst.Text & "\" & txtEst.Text & "-Meth-" & File1.FileName
        FileCopy Me.AcrobatPath, strDest
        End If
    Next i
MsgBox "All Files Transferred", vbInformation, ""
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Loop through FileListBox

Post by HansV »

File1.FileName only works if the filelistbox is set to single selection. If it is set to one of the multiple selection options, use File1.List(i) in your For i ... Next i loop.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Loop through FileListBox

Post by D Willett »

EDITED ( AcrobatPath needs to change - Just seen It)
Like so:?
This seems to copy the same file over but renames it as the selection ?

Code: Select all

If Me.TreeView1.SelectedItem.Text = "" Then
MsgBox "No Vehicle Selected", vbInformation, ""
Exit Sub
End If

If Me.File1 = "" Then
MsgBox "No Method Selected", vbInformation, ""
Exit Sub
End If

    Dim N As String
    Dim strDest As String
    Dim i As Integer
    
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
        strDest = "L:\mmpdf\ConsoleFiles\" & txtEst.Text & "\" & txtEst.Text & "-Meth-" & File1.List(i)
        FileCopy Me.AcrobatPath, strDest
        End If
    Next i
MsgBox "All Files Transferred", vbInformation, ""
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Loop through FileListBox

Post by HansV »

Er, what is the current status of the question?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Loop through FileListBox

Post by D Willett »

Hi Hans
I have to change the source document which is "AcrobatPath". The filename changes in the loop (strDest) and a document is saved for each filename.
If AcrobatPath doesn't change then the file is the same regardless of how it is named during FileCopy.

AcrobatPath is set before the loop filelist routine. So I need to get the full source path from the treeview control and then add the filename to it to give me a full source path. I could do this like thefollowing but the source file is still the same one being copied: Just trying to work it out :scratch:

Code: Select all

If Me.TreeView1.SelectedItem.Text = "" Then
MsgBox "No Vehicle Selected", vbInformation, ""
Exit Sub
End If

If Me.File1 = "" Then
MsgBox "No Method Selected", vbInformation, ""
Exit Sub
End If

    Dim N As String
    Dim strSource As String
    Dim strDest As String
    Dim i As Integer
    
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
        strSource = Me.TreeView1.SelectedItem.FullPath & "\" & File1.List(i)
        strDest = "L:\mmpdf\ConsoleFiles\" & txtEst.Text & "\" & txtEst.Text & "-Meth-" & File1.List(i)
       Debug.Print Me.AcrobatPath, strDest
        End If
   Next i
MsgBox "All Files Transferred", vbInformation, ""
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Loop through FileListBox

Post by HansV »

Shouldn't it be

Code: Select all

        FileCopy strSource, strDest
(It's not clear to me what role AcrobatPath plays)
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Loop through FileListBox

Post by D Willett »

Doh ....

Why didn't I see that :groan:

This works:

Code: Select all

        If File1.Selected(i) Then
        strSource = "L:\" & Me.TreeView1.SelectedItem.FullPath & "\" & File1.List(i)
        strDest = "L:\mmpdf\ConsoleFiles\" & txtEst.Text & "\" & txtEst.Text & "-Meth-" & File1.List(i)
       FileCopy strSource, strDest
Cheers ...

Dave.