Consulting

Results 1 to 14 of 14

Thread: Solved: Using TextBox1 to MkDir Name

  1. #1

    Solved: Using TextBox1 to MkDir Name

    I am trying to automate a process that gets an unknown number of files ready to send to another company. It needs to be done once a month. What I would like to do is get the user to supply a name in a UserForm (UserForm3) TextBox (TextBox1) for the name of the directory where it would be stored. For example: 15Feb2006Ver1, where it would go out to the network under K:\History\15Feb2006Ver1. I would also like to create two subdirectories under this new directory. I have everything down except how to code the textbox and then use it to name the directory.

    Dim HistoryDir as String
    UserForm3.Show

    Set HistoryDir = Textbox1.Value
    MkDir ("K:\History\&HistoryDir")

    Obviously, it's not working. Any help would be appreciated.
    Thanks!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You just need to break the variable out of the text string.

    [VBA] MkDir ("K:\History\" & HistoryDir)[/VBA]

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    You don't need the Set for a string variable, in fact it'll probably cause errors.
    [vba]
    Dim HistoryDir as String
    UserForm3.Show

    HistoryDir = Textbox1.Value
    MkDir "K:\History\" & HistoryDir
    [/vba]

  4. #4
    I get the error messge "Object Required". Is there something in the code for the actual TextBox1 that I'm missing. Many thanks.

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Where is this code located?

  6. #6
    Also how would I set a subdirectory?

    MkDir "k:\History\" & HistoryDir & "\CPT"

    Thanks again!

  7. #7
    I don't have any code. Is that the problem. This is the first time I've used anything for user input.

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I'm getting confused here.

    What do you actually have?

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    se

    [vba]
    Dim HistoryDir As String
    UserForm3.Show

    HistoryDir = UserForm3.Textbox1.Value
    MkDir "K:\History\" & HistoryDir
    [/vba]

    but make sure that your form is not unloaded, but just hidden whenyou exit

  10. #10
    That did it. It worked perfectly. Do you know how to do the subdirectories?

    MkDir "k:\History\" & HistoryDir & "\CPT" ???

    Thank you!

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    For the subdirectory you need to create the directory, then the subdirectory.
    [vba]
    Dim HistoryDir As String
    UserForm3.Show

    HistoryDir = UserForm3.Textbox1.Value
    MkDir "K:\History\" & HistoryDir
    MkDir "K:\History\" & HistoryDir & "\CPT"[/vba]

  12. #12
    Perfection!!! Thank you so much!

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by SherryO
    That did it. It worked perfectly. Do you know how to do the subdirectories?

    MkDir "k:\History\" & HistoryDir & "\CPT" ???

    Thank you!
    I work my way down the directory

    [vba]
    Sub MakeDirectories()
    Const sDirs As String = "C:\History\HistoryDir\CPT"
    Dim aryDirs
    Dim iStart As Long, i As Long
    Dim sDir As String

    aryDirs = Split(sDirs, "\")
    If Right(aryDirs(0), 1) = ":" Then
    sDir = aryDirs(0)
    iStart = 1
    Else
    sDir = CurDir
    iStart = 0
    End If

    For i = iStart To UBound(aryDirs)
    sDir = sDir & "\" & aryDirs(i)
    If Len(Dir(sDir, vbDirectory)) = 0 Then
    MkDir sDir
    End If
    Next i

    End Sub
    [/vba]

  14. #14
    Thank you for your post, unfortunately, you completely lost me. The MkDir is working great. Thanks anyway.
    SherryO

Posting Permissions

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