Creating directories!

R

Rich Skruch

I'll answer for Rich.

It's considered good practice to clean up after yourself, in an attempt to
prevent memory leaks. You're correct that the objects in question should be
deleted from memory when the code finished, but many of us prefer to ensure
it happens, rather than hope it will!

Thanks. I was away from the newsgroups yesterday and didn't get a
chance to follow up. You explained it better than I could have, anyway.

Rich.
 
R

Rich Skruch

Hello Rich

Having said that your code worked a treat, that was when I was on my 'other' PC: now I'm back on the main PC it won't work!!

The code I now have is:
Public Sub MakeFolders()

Dim sFolder As String
Dim rst As DAO.Recordset
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set rst = CurrentDb.OpenRecordset("practices")

Do While Not rst.EOF

sFolder = rst![prac name]
Set f = fs.CreateFolder("C:\Clients\" & sFolder)
rst.MoveNext

Loop

rst.Close
Set f = Nothing
Set rst = Nothing
Set fs = Nothing

End Sub

... and this keeps giving me:
Run-time error 52
Bad command or file number
with the following line:
Set f = fs.CreateFolder("C:\Clients\" & sFolder)
highlighted in yellow.

I even tried using:
Set f = fs.CreateFolder("C:\" & sFolder)
for the destination, but got the same result.

Hope you can advise.
Many thanks
Les

I see in the other branch of this thread that there was a "." in one of
the names. Did that fix the problem here? I couldn't reproduce the
error on my machine, with various folder names, with or without periods.

Rich.
 
L

Leslie Isaacs

Rich
Although I did have some cases with a "." in the name, and subsequently
removed them, it was in fact a "*" that was causing the problem!!
Anyway, all's well now, and I am very grateful for your help.
Les.


Rich Skruch said:
Hello Rich

Having said that your code worked a treat, that was when I was on my 'other' PC: now I'm back on the main PC it won't work!!

The code I now have is:
Public Sub MakeFolders()

Dim sFolder As String
Dim rst As DAO.Recordset
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set rst = CurrentDb.OpenRecordset("practices")

Do While Not rst.EOF

sFolder = rst![prac name]
Set f = fs.CreateFolder("C:\Clients\" & sFolder)
rst.MoveNext

Loop

rst.Close
Set f = Nothing
Set rst = Nothing
Set fs = Nothing

End Sub

... and this keeps giving me:
Run-time error 52
Bad command or file number
with the following line:
Set f = fs.CreateFolder("C:\Clients\" & sFolder)
highlighted in yellow.

I even tried using:
Set f = fs.CreateFolder("C:\" & sFolder)
for the destination, but got the same result.

Hope you can advise.
Many thanks
Les

I see in the other branch of this thread that there was a "." in one of
the names. Did that fix the problem here? I couldn't reproduce the
error on my machine, with various folder names, with or without periods.

Rich.
 
Top