Results 1 to 3 of 3

Thread: Copying a file

  1. #1
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169

    Unanswered: Copying a file

    Hi right, i hope someone has come across this before.

    Im making a database where i need to add attachments, the problem i face is that when ive chosen the attachement i want to add then i want to copy it to a new location, in case the original attachement gets moved or deleted, i want to move it to a folder i create.

    Ive got as far as picking the file and i can get the source to copy but i cant get the destination.

    So far i have got

    Dim Source as string
    Dim Dest as string

    Forms![Attachment].AttFileLoc = GetOpenFile
    source = Forms!Attachment!AttFileLoc
    dest = "S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName

    If Not Len(Dir("S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName, vbDirectory)) > 0 Then

    MkDir "S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName
    FileCopy source, dest
    Else
    FileCopy source, dest
    End If
    Exit Sub

    See this doesnt work because i need to tell the destination what the filename is that i want to call it? How do i get the filename from the source?

    Ive experimented with the left function and the right function trying to trap the first "\" i come to but im not having much luck with that at all?

    Can anyone help please?
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  2. #2
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Its ok ive sorted it out
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  3. #3
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    For those of you interested, here is the new code


    Dim length As Integer
    Dim source As String
    Dim dest As String
    Dim LeftName As Integer
    Dim RightName As String
    Dim location As Integer


    Forms![Attachment].AttFileLoc = GetOpenFile
    length = Len(Forms!Attachment!AttFileLoc)
    location = InStrRev(Forms!Attachment!AttFileLoc, "\")

    LeftName = length - location
    RightName = Right(Forms!Attachment!AttFileLoc, LeftName)
    source = Forms!Attachment!AttFileLoc
    dest = "S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName

    If Not Len(Dir("S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName, vbDirectory)) > 0 Then

    MkDir "S:\StarScanner\Patients\" & Forms![Patient Form]!BabyName
    FileCopy source, dest & "\" & RightName
    Forms!Attachment!AttFileLoc = dest & "\" & RightName
    Else
    FileCopy source, dest & "\" & RightName
    Forms!Attachment!AttFileLoc = dest & "\" & RightName
    End If
    Exit Sub[/Code]
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

Posting Permissions

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