Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I dynamically create a directory? 1

Status
Not open for further replies.

nkdoshi

IS-IT--Management
Sep 12, 2000
7
US
How to I dynamically create a directory under the C: drive based on user input?

For example, if a user named "Bob" enters his name into a form and clicks on a button, how do I get that button to create the folder "C:\Bob"?

Any help would be appreciated!
Thanks,
NKDOSHI [sig][/sig]
 

Another way:

Dim FSO As Scripting.FileSystemObject
Dim FS As Scripting.Folders
Dim F As Scripting.Folder

Set FSO = New Scripting.FileSystemObject
Set F = FSO.CreateFolder("c:\TestFolder")

To simplify things you can make a Reference to Microsoft Scripting Language and you'll see a load of stuff on Drives, Folders, Files, etc. It is quite a nice library!

If you make a Project Reference then you can drop the "Scripting." Prefix and then it's more readable!
[sig][/sig]
 
VB400 is right. If you want to keep it simple use MkDir("dirname"), but if you REALLY want to work with files and folders, lookup FileSystemObject.

It's neet. [sig][/sig]
 
Thanks for your help! The problem is that MkDir only creates a directory that you hardcode in. It will not create a directory from a user input.

The other problem is that I have used the following code to make the directory I want, but it only works on Win 98 NOT Win NT. I am using Access 97 and have administrator rights to the machine.

Dim fs, f, f1, fc, S, secfolder
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\asqhold")
Set fc = f.SubFolders
fc.Add [Form_Personal Data]!Name

I always get the error "Active X can't create object." Is there another way complete this action? Or does anyone know why this doesn't work on NT??

Thanks!
NkDoshi [sig][/sig]
 

NkDoshi,

If your form name is "Personal Data" then change the last line to read as follows:

fc.Add Forms![Personal Data]!Name

The code that I shared earlier definitely works with NT so I don't think that it is a platform issue! [sig][/sig]
 
Well I tried that change and I still get the error "Active X can't create object". Then I tried your previous code and got the following:

Compile Error:
User-defined type not defined

It doesn't seem to like " Dim FSO As Scripting.FileSystemObject"

Do I need an additional reference? If so why because I don't need one on Win98?

Thanks so much for the help!
nkdoshi
[sig][/sig]
 

Sorry about that!

Make a reference to "Microsoft Scripting Runtime" which is the DLL: C:\WINNT\System32\SCRRUN.DLL

or instead use this code and you don't have to make any references:

Dim FSO, F
Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.CreateFolder("c:\TestFolder")

[sig][/sig]
 
Thanks so much!! The problem was that the system did not even have the scrrun.dll. I had to copy it from another machine and manually register it into the Windows Registry! But now my original code works just fine. Thanks again for your help :-D [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top