The Error 75 is probably because C:\New Folder\Leslie already exists. Try
deleting the folder, then running
Sub makedirs()
MkDir "C:\New Folder\Leslie"
End Sub
just to see whether it's a VBA issue or not.
Sorry, but I'm out of ideas. As I said, it works fine for me.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Douglas
This is getting strange!
This works fine
MkDir "C:\New Folder\Leslie"
and this worked fine:
Sub makedirs()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT [prac name] FROM practices")
Do While rsCurr.EOF = False
Debug.Print "C:\New Folder\" & rsCurr![prac name]
rsCurr.MoveNext
Loop
End Sub
(looking in (Ctrl-G) showed all the expected names)
But this doesn't work:
Sub makedirs()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT [prac name] FROM practices")
Do While rsCurr.EOF = False
MkDir "C:\New Folder\Leslie"
rsCurr.MoveNext
Loop
End Sub
I get:
Run-time error '75'
Path/file access error
If I try it with:
MkDir "C:\New Folder\" & rsCurr![prac name]
I get:
Run-time error '76'
Path not found
I very much hope something in all this means something to you, because I'm
bewildered!
Many thanks again
Les.
Douglas J. Steele said:
Works fine for me...
First, make sure that your query is returning what you think it should.
Replace
MkDir "C:\New Folder" & rsCurr![prac name]
with
Debug.Print "C:\New Folder\" & rsCurr![prac name]
then look in the Immediate window (Ctrl-G) to see that it's correct.
Next, try going into the immediate window and manually run
MkDir "C:\New Folder\Leslie"
and see whether it creates a folder for you.
BTW, assuming you want this to produce subfolders underneath C:\New
Folder,
you need a terminating slash:
MkDir "C:\New Folder\" & rsCurr![prac name]
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Leslie Isaacs said:
Hello Douglas
Many thanks for persevering with this!
I took the Chr$(34) out, so now I have:
Sub makedirs()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT [prac name] FROM Practices")
Do While rsCurr.EOF = False
MkDir "C:\New Folder" & rsCurr![prac name]
rsCurr.MoveNext
Loop
End Sub
.. but I still get the same error.
In case the problem was somethinbg to do with the fact that my field
name
in
Practices has a space (which is why I put the square brackets round it),
I
tried another field name instead of [prac name] - one without the space,
and
removed the square brackets around it, but again I got the same error.
What else can it be?
Hope you'll stay with me on this!
Les.
Oops, sorry. I didn't bother testing before posting.
Turns out you don't need the Chr$(34) after all.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hello Douglas
Thank you for your reply.
I tried the code that you suggested, with a slight change to the
filed
name
and path, so now I have:
Sub makedirs()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT [prac name] FROM
Practices")
Do While rsCurr.EOF = False
MkDir Chr$(34) & "C:\New Folder\" & rsCurr![prac name] & Chr$(34)
rsCurr.MoveNext
Loop
End Sub
... but when I ran it I got the message:
Run-time error 76
Path not found
with the line:
MkDir Chr$(34) & "C:\New Folder\" & rsCurr![prac name] & Chr$(34)
highlighted in yellow.
I definitely have a folder called New Folder directly under the C
drive -
I
even copied and pasted the path (C:\New Folder) from the address bar
at
the
top of the windows explorer screen.
I'm sure it's something simple (?) but cannot see it myself.
I am very grateful for your continued help.
Les.
message
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset("SELECT member_name FROM
Members")
Do While rsCurr.EOF = False
MkDir Chr$(34) & "C:\Documents and Settings\Members\" &
rsCurr!member_name & Chr$(34)
rsCurr.MoveNext
Loop
(I've included the Chr$(34) in case member_name contains blanks)
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Hello Joel
Thanks for your reply.
Sorry about my ignorance: how would I use MkDir "C:\monkey" to
create
directories with names taken from my access table? And can they
all
(around
120 of them) be created at once, or must it be one at a time (in
which
case
I might as well do it manually!)?
Thanks for your continued help.
Les.
Leslie,
The command you need to use is like this:
MkDir "C:\monkey"
-Joel
Hello All
I need to create a new directory on my PC (under My
Documents>Members)
for
each [member_name] in table Members.
Is there any way of doing this automatically, with code? I'm
sure
there
is,
but my VBA isn't up to it!
Hope someone can help.
Many thanks.
Leslie Isaacs