Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Directory Creation (97 SR2)

    Hey guys, I am moving files using a "filecopy" code provided to me by Pat. I have found that the file won't copy unless the directory structure is in place. So, I'd like to know if there is code that I can precede this with that will create a directory. The directory I want to copy my files to does not exist, I currently have to go in and manually create it before running the code. I will post a sample of the code I'm using.

    Function File_Copy()

    Dim dbs As DAO.Database, rs As DAO.Recordset
    ' Set up objects for the database and the recordset
    Set dbs = CurrentDb
    Set rs = dbs.OpenRecordset("File Copy")
    ' While there is data in the recordset
    Do While Not rs.EOF
    ' Copy from InputFilename to OutputFilename
    FileCopy rs!InputFilename, rs!DestFilename
    ' Get the next record from the recordset
    rs.MoveNext
    Loop
    ' Clean up after ourselves, this releases memory back to windows
    Set rs = Nothing
    Set dbs = Nothing

    End Function

    Thanks in advance!
    KST

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

    Re: Directory Creation (97 SR2)

    There is the "old-fashioned" Basic instruction MkDir "C:Test"

    And if you set a reference to Microsoft Scripting Runtime (in Tools/References...), you can use the FileSystemObject; which has a method CreateFolder:

    Dim fso As Scripting.FileSystemObject
    fso.CreateFolder "C:Test"

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Hans,

    That directory name would need to be controled by a field in a form. So, would I need more code to make that happen, similar to the code that I have for "File Copy"?
    I am moving image files, and I need the customer name to be the directory name. ex: N:1_Client JPG FilesTidmore, Scott 5462Tidmore,Scott001.jpg

    The name of the directory would be controled by the form that has focus.

    Thanks for your quick response.
    KST

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

    Re: Directory Creation (97 SR2)

    I used string constants in my reply as an example, you can use string variables or expressions as well. If the client name is in a text box named txtClient on the form, you can use

    MkDir "N:1_Client JPG Files" & Me.[txtClient]

  5. #5
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Thanks Hans! I think that'll work! I appreciate the quick assistance!

    KST

  6. #6
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Hans,

    I'm getting an "Invalid Use Of Me Keyword" error. I tried to exchange the Me keyword for the full path, example: Forms![Post Proof Move Info]![JPG Directory Name] .

    That did not work either. Let me know your thoughts on what I'm doing wrong.

    Thanks again for the help.
    KST

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

    Re: Directory Creation (97 SR2)

    What was the error message when you used Forms! etc. ?

    Is Post Proof Move Info an opened main form (not a subform) when you are running this code?

  8. #8
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Hans,

    The error message with using the code MkDir ("N:1A_Client JPG Files" & Forms![Post Proof Move Info]![JPG Directory Name])
    is Runtime Error '75 Path/File access error.

    Yes, Post Proof Move Info is the main (only) form that is up when I click the command button to run the code. When I debug, the MkDir line is yellow.

    And, of course when I use the 'Me' command, I get an error as well.

    Thanks for your help.
    KST

  9. #9
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Hans, disregard last post..... I think I got an error, because it worked the first time, and I got an error on the second part of the code. In essence, I had already created the directory by using the code you provided. When I went to run it again, I got an error, because the directory already existed. So, your code worked, and I am having problems with another portion of the project.

    I'll reply back shortly to let you know if I have completely resolved the issue. Sorry for the mistake, and thanks for your time.
    KST

  10. #10
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Carrollton, Georgia, USA
    Posts
    123
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Directory Creation (97 SR2)

    Hans,

    I found the problem, it was just no less than 3 typing errors on my part. The code you provided solved my problem from the begining, but the other issues kept me from realizing it.

    Thanks again for your swift assistance today. Have a good one!
    KST

Posting Permissions

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