?
Solved

MKDIR in Access 2007

Posted on 2009-07-07
6
Medium Priority
?
1,057 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:Robert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:bboswell
ID: 24800649
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.

0
 

Author Comment

by:Robert
ID: 24800848
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

0
 
LVL 5

Expert Comment

by:bboswell
ID: 24801825
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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Robert
ID: 24803613
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
0
 
LVL 5

Accepted Solution

by:
bboswell earned 2000 total points
ID: 24803848
I have attached a Snippet of Code I use to Create Folders if they don't exit.

Can be used as follows:

cmdtxt = "CD c:\'" + dirname + "'"
CreateDirIfRequired(cmdtxt)
'Function to Create Directorys
Function CreateDirIfRequired(strMyPath As String)
If Len(Dir(strMyPath, vbDirectory)) = 0 Then
    MkDir strMyPath
End If
End Function
 
cmdtxt = "CD c:\'" + dirname + "'"
CreateDirIfRequired(cmdtxt)

Open in new window

0
 

Author Comment

by:Robert
ID: 24804223
Excellent!  
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question