Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Create Folder from field entry (2000)

    Hi everyone.

    I was wondering how to create a folder from a field entry. i.e. a field called Field1 has Jan09 typed into it, then a button next to it is is hit by the user, and hey presto, a folder is created called Jan09 on the c drive? Is this at all possible?

    Many thanks

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

    Re: Create Folder from field entry (2000)

    You can use the following instruction in the On Click event procedure of the button:

    MkDir "C:" & Me.Field1

    MkDir stands for Make Directory (=folder)

  3. #3
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    Hans.

    As ever, many thanks

    Just out of interest, how would I combine to fields to create a folder. i.e. Field1 has 2006 and Field2 has Jan... and the resulting directory would be c:2006Jan ?

    many thanks

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

    Re: Create Folder from field entry (2000)

    You can use the concatenation operator & to piece together the individual parts:

    <code>MkDir "C:" & Me.Field1 & "" & Me.Field2</code>

  5. #5
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    I tried everything but that!!! Must be Friday afternoon!! Thanks Hans.

  6. #6
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    sorry Hans, but it comes up with "Can't find path" and I can't really work out why, as MkDir is exactly that, not Find Directory!

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    You have to do this in two steps.
    MkDir "C:" & Me.Field1
    to create the first directory and then
    MkDir "C:" & Me.Field1 & "" & Me.Field2
    Francois

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

    Re: Create Folder from field entry (2000)

    You can only create a folder C:2006Jan if the parent C:2006 already exists. So perhaps the error message indicates that the folder C:2006 couldn't be found. You could use
    <code>
    MkDir "C:" & Me.Field1
    MkDir "C:" & Me.Field1 & "" & Me.Field2
    </code>
    This way, you only add one level each time.

  9. #9
    Lounger
    Join Date
    Apr 2002
    Location
    Salem, New Hampshire, USA
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    Is it possible that field1 is a number field?

    If yes, then you need to convert 2006 to a string?

    MkDir "C:" & Str(Me.Field1)
    MkDir "C:" & Str(Me.Field1) & "" & Me.Field2

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

    Re: Create Folder from field entry (2000)

    Visual Basic is very lenient (or lax, depending on your point of view) - if you concatenate string values and numeric values, the numbers will automatically be converted to strings.

    If you do want to convert to string explicitly, it's better to use CStr, for Str will prefix non-negative numbers with a space, i.e. Str(37) results in <code>"

  11. #11
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    Thanks guys. This is now working nicely. Once other point. Using this information, i've also created a hyperlink field that then displays the path of the folder created, but i'm not sure how to get it to open in Explorer?

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

    Re: Create Folder from field entry (2000)

    How are you populating the hyperlink field?

  13. #13
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    Private Sub Cmd_Create_Folder_Click()
    On Error Resume Next
    MkDir "C:" & Me.DateYear
    MkDir "C:" & Me.DateYear & "" & Me.DateMonth
    MkDir "C:" & Me.DateYear & "" & Me.DateMonth & "" & Me.ID
    Me.FilePath = "C:" & Me.DateYear & "" & Me.DateMonth & "" & Me.ID & ""
    End Sub

    FilePath is the hyperlink field. It creates the file path and displays it correctly, but the link doesn't open.

    Many thanks

    Thom

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

    Re: Create Folder from field entry (2000)

    Hyperlink fields are of the form a#b#c where
    a = display text (if a is empty, b is displayed)
    b = hyperlink address
    c = hyperlink subaddress (can be empty)

    So try

    Me.FilePath = "#C:" & Me.DateYear & "" & Me.DateMonth & "" & Me.ID & "#"

  15. #15
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Create Folder from field entry (2000)

    Brilliant. thanks Hans. Works a treat now.

Posting Permissions

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