Solved

MKDIR in Access 2007

Posted on 2009-07-07
6
1,046 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
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:bboswell
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Robert
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Excellent!  
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now