Link to home
Start Free TrialLog in
Avatar of Robert
RobertFlag for United States of America

asked on

MKDIR in Access 2007

Hi -

Trying to create a sub-directory c:\xxx\yyy from an Access 2007 form, where a new record is added, and the ..\yyy\ subdirectory needs to be created.

I see that the Shell function in VBA will run a command-line, but I can't seem to do two things - pull the text string from the form field [Y1] and put it in a string to execute Shell(cmdtxt);  and, figuring out the right command-line to emulate "MKDIR c:\xxx\yyy"

Help!

ub
Avatar of bboswell
bboswell

You can just use the "MKDIR" Function.

MKDIR "C:\XXX\YYY"

Directory XXX would have to be there first, I would also check first to make sure that YYY does not already exist.

Avatar of Robert

ASKER

The directory never shows up.  I get runtime error '53':   File not found

 Maybe it's syntax?  I've tried a few different ways.  

The Msgbox shows that flow follows the On Error trapping.
Private Sub Command1_Click()
  dirname = "Joliet Marketers"
  cmdtxt = "CD c:\'" + dirname + "'"
  On Error GoTo MakeDir
  MsgBox cmdtxt
  one = Shell(cmdtxt)
  Exit Sub
  
MakeDir:
  cmdtxt = "MkDir c:\" + dirname
   MsgBox cmdtxt
  one = Shell(cmdtxt)
End Sub

Open in new window

OK you dont need to "SHELL" the MKDIR command.

So see I replaced the "one = Shell(cmdtxt)" at the end.
Private Sub Command1_Click()
  dirname = "Joliet Marketers"
  cmdtxt = "CD c:\'" + dirname + "'"
  On Error GoTo MakeDir
  MsgBox cmdtxt
  one = Shell(cmdtxt)
  Exit Sub
  
MakeDir:
  cmdtxt = "MkDir c:\" + dirname
   MsgBox cmdtxt
  'one = Shell(cmdtxt)
  MkDir ("c:\" & dirname)
End Sub

Open in new window

Avatar of Robert

ASKER

Huh!  So the previous Shell to test by:
cmdtxt = "CD c:\'" + dirname + "'"
doesn't really work as designed, either.

However, CD ("c:\" + dirname) does not work.  How can I check for the folder before creating it?
MKDIR works, CD doesn't?  

I'm not sure I understand what Shell actually does - I thought it allows running command-line programs.  

ub
ASKER CERTIFIED SOLUTION
Avatar of bboswell
bboswell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert

ASKER

Excellent!