Results 1 to 8 of 8

Thread: File Copy (B6)

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

    File Copy (B6)

    I've been writing this code today, which halts and errors "File Not Found" in the filecopy statement.
    I think the problem lies with the ListBox.
    Although FN returns a value, I'm not sure if anything is properly selected from the list or not.
    The listbox gives the user the ability to use a checkbox on each item and those which return true
    should be transfered or copied to a path.


    <pre>Dim JN As String 'Job Number
    Dim RN As String 'Registration Number
    Dim FN As String 'FileName
    Dim N As Integer 'Number
    Dim DP As String 'Default Path

    JN = InputBox("Job Number", "")
    RN = InputBox("Registration No", "")
    DP = "C:BICImage"

    If JN = "" Or RN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & _
    vbCrLf & "Please Try Again": Exit Sub
    End If
    For N = 0 To lstImages.ListCount - 1
    FN = UCase$(JN) + "-" + RN + "_" + lstImages.List(N)
    MsgBox DP & FN '******** Returns correct path and only first item in list *******


    FileCopy lstImages.List(N), DP & FN
    Next N</pre>


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

    Re: File Copy (B6)

    The error lay partly with the common dialog commands.
    The code populates lstImages with "Path" & " Filename", (L:|BICImage15.jpg) so when I try to filecopy later in the code, I was trying to push two Paths along with it: (C:BICImageL:BICImage15.jpg)

    I supressed the dialog from populating the list with the location path:

    myPath = myFiles(0) & IIf(Right(myFiles(0), 1) <> "", "", "") & myFiles(i)

    to

    myPath = myFiles(i)

    So the list only populates with the filename only, adding the destination after the filecopy command.
    It now works.

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

    Re: File Copy (B6)

    And just when you thought it was safe to go back in the water !!!!!!!!

    The only problem now is, it doesn't matter what is selected from the list, ALL items in the list are exported.

    I think I need to add lstImages.Selected(N) somewhere, but where ???

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: File Copy (B6)

    Try

    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    FN = UCase$(JN) + "-" + RN + "_" + lstImages.List(N)
    MsgBox DP & FN
    FileCopy lstImages.List(N), DP & FN
    End If
    Next N

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

    Re: File Copy (B6)

    Hans
    Thank you very much.
    I knew I wasn't far off.

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

    Re: File Copy (B6) -Revisited

    One little glitch seems to be happening here.
    If the first item in the list is not selected, the code will not export the images.
    If I have six images in the list, and I select all but the first one, the msgbox "No Images Selected" fires unless I select the first item.
    Is there an alternative to the below code which will remedt this ?

    <pre>Private Sub cmdExport_Click()
    Dim JN As String 'Job Number
    Dim RN As String 'Registration Number
    Dim FN As String 'FileName
    Dim n As Integer 'Number
    Dim DP As String 'Default Path

    On Error Resume Next
    If lstImages.ListCount = 0 Then
    MsgBox "No Images To Select", , ""
    Exit Sub
    End If

    If lstImages.Selected(n) = 0 Then
    MsgBox "No Images Selected", , ""
    Exit Sub
    End If

    JN = InputBox("Job Number", "")
    RN = InputBox("Registration No", "")
    DP = "L:MMPDFImage"

    If JN = "" Or RN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & vbCrLf & "Please Try Again", , "": Exit Sub
    End If

    For n = 0 To lstImages.ListCount - 1
    If lstImages.Selected(n) Then
    FN = UCase$(JN) + "-" + RN + "_" + lstImages.List(n)

    FileCopy lstImages.List(n), DP & FN
    End If
    Next n

    MsgBox "Images Exported", , ""
    ClearList
    End Sub</pre>


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

    Re: File Copy (B6) -Revisited

    Instead of testing for lstImages.Selected(n) = False, you can test for lstImages.SelCount = 0. SelCount returns the number of selected items.

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

    Re: File Copy (B6) -Revisited

    Thankyou Hans
    Perfect

Posting Permissions

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