View Full Version : Solved: Using TextBox1 to MkDir Name
SherryO
01-30-2006, 01:51 PM
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!
Jacob Hilderbrand
01-30-2006, 02:17 PM
You just need to break the variable out of the text string.
MkDir ("K:\History\" & HistoryDir)
Norie
01-30-2006, 02:24 PM
You don't need the Set for a string variable, in fact it'll probably cause errors.
Dim HistoryDir as String
UserForm3.Show
HistoryDir = Textbox1.Value
MkDir "K:\History\" & HistoryDir
SherryO
01-31-2006, 06:37 AM
I get the error messge "Object Required". Is there something in the code for the actual TextBox1 that I'm missing. Many thanks.
Norie
01-31-2006, 06:40 AM
Where is this code located?
SherryO
01-31-2006, 06:40 AM
Also how would I set a subdirectory?
MkDir "k:\History\" & HistoryDir & "\CPT"
Thanks again!
SherryO
01-31-2006, 06:41 AM
I don't have any code. Is that the problem. This is the first time I've used anything for user input.
Norie
01-31-2006, 06:50 AM
I'm getting confused here.:)
What do you actually have?
Bob Phillips
01-31-2006, 06:52 AM
se
Dim HistoryDir As String
UserForm3.Show
HistoryDir = UserForm3.Textbox1.Value
MkDir "K:\History\" & HistoryDir
but make sure that your form is not unloaded, but just hidden whenyou exit
SherryO
01-31-2006, 06:55 AM
That did it. It worked perfectly. Do you know how to do the subdirectories?
MkDir "k:\History\" & HistoryDir & "\CPT" ???
Thank you!
Norie
01-31-2006, 07:01 AM
For the subdirectory you need to create the directory, then the subdirectory.
Dim HistoryDir As String
UserForm3.Show
HistoryDir = UserForm3.Textbox1.Value
MkDir "K:\History\" & HistoryDir
MkDir "K:\History\" & HistoryDir & "\CPT"
SherryO
01-31-2006, 07:04 AM
Perfection!!! Thank you so much!
Bob Phillips
01-31-2006, 11:05 AM
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
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
SherryO
01-31-2006, 11:13 AM
Thank you for your post, unfortunately, you completely lost me. The MkDir is working great. Thanks anyway.
SherryO
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.