Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Send Files (VB6)

    I get a "File not found error with the following code, what could be wrong with it ?

    <pre>Private Sub cmdSend_Click()
    Dim AF As String
    Dim n As Integer
    AF = "L:MMPDFArchive"
    For n = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(n) Then
    FileCopy lstFiles.Selected(n), AF & lstFiles.Selected(n)

    End If
    Next n
    End Sub</pre>


  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    You are trying to copy lstFiles.Selected(n); this is a boolean True/False that indicates whether the n-th item is selected, it is not a file name. You want lstFiles.List(n) instead.

    Note: you are specifying a path (in the variable AF) for the destination, but not for the source. If the list box items don't contain the path, the files may not be found if the source folder is not the current directory, and if the list items DO contain the path, concatenating with AF will cause an error.

  4. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Getting closer: Oject required error 424

    <pre>Private Sub cmdSend_Click()
    Dim SF As String ' Source Folder
    Dim AF As String ' Archive Folder
    Dim N As Integer ' Number
    Dim FN As String ' FileName
    Dim DP As String ' Default Path


    SF = "L:MMPDFEstPdf"
    AF = "L:MMPDFArchive"



    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    FN = lstImages.List(N)
    FileCopy lstFiles.List(N), SF & FN
    End If
    Next N
    End Sub</pre>


  5. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    I modified the code some, but no files are exported:

    <pre>Dim FN As String 'FileName
    Dim N As Integer 'Number
    Dim AF As String 'Archive Folder
    Dim SP As String 'Source Path

    On Error Resume Next
    If lstFiles.ListCount = 0 Then
    MsgBox "No Files To Select", , "Information"
    Exit Sub
    End If

    If lstFiles.SelCount = 0 Then
    MsgBox "No Files Selected", , "Information"
    Exit Sub
    End If

    AF = "L:MMPDFArchive"
    SP = "L:MMPDFEstPDF"
    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)
    FileCopy lstFiles.List(N), AF & FN
    End If
    Next N

    MsgBox "Files Archived", , "Information"
    lstFiles.Clear
    Unload Me</pre>


  6. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    Why have you switched from lstFiles to lstImages?

  7. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    Try replacing

    FileCopy lstFiles.List(N), AF & FN

    by

    FileCopy SP& FN, AF & FN

    If that doesn't work, set a breakpoint and single-step through the code. Hover the mouse over the variables to see their value and try to locate unexpected values.

  8. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Still no go.
    I've stepped thru and keep getting "Path not found 76" but the paths are correct:

    <pre>Dim SF As String ' Source Folder
    Dim AF As String ' Archive Folder
    Dim N As Integer ' Number
    Dim FN As String ' FileName

    SF = "L:MMPDFEstPdf"
    AF = "L:MMPDFArchive"
    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)
    'FileCopy lstFiles.List(N), SF & FN
    FileCopy SF & FN, AF & FN

    End If
    Next N

    End Sub</pre>


  9. #8
    Lounger
    Join Date
    Jan 2004
    Location
    Prague, Czech Republic
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Hi Dave,
    did you try to hard-code one copy procedure e.g. in the immediate window?
    Something like

    FileCopy "C:test.dat", "Catatest.dat"

    If there's an error, it has something to do with the path specification or maybe access to the folder.
    If it runs OK, the problem is probably the filename you got from your listbox.
    Regards,
    Martin

  10. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    Dave,

    Temporarily make the line FileCopy SF & FN, AF & FN into a comment, and insert a new line

    Debug.Print SF & FN, AF & FN

    immediately above it. When you run the code by clicking the cmdSend button, the file paths will be written to the Immediate window (can be activated by pressing Ctrl+G in the Visual Basic Editor)
    What do you see in the Immediate window?

  11. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Using debug.print the following as per attached png:

  12. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Got it:

    Me.lstFiles.AddItem fil.Name & " " & fil.DateLastModified

    This is how the list is populated, removing the DateLastModified enabled the transfer to take place. <img src=/S/woops.gif border=0 alt=woops width=58 height=36>

  13. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

  14. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Ironic isn't it !

    Sometimes you just can't see for the trees !!

    p.s

    Don't suppose you know a way to zip the files before they are sent do you ?

  15. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Send Files (VB6)

    If you have a registered version of WinZip 8.0 or higher, you can download the command line extension here without additional cost. You can control the command line extension from your VB program.

  16. #15
    Lounger
    Join Date
    Jan 2004
    Location
    Prague, Czech Republic
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Files (VB6)

    Hi Dave,
    a) you can also extract the name by combining Left and InStr functions. No need to remove the FileModified info.
    [img]/forums/images/smilies/cool.gif[/img] re ZIP & MAIL: Have a look here
    Regards,
    Martin

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •