By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,291 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,291 IT Pros & Developers. It's quick & easy.

MKDIR In VB ??

P: 36
Hi All,

When i run below code It's not creating folder.... In can see it in msgbox prompt it showing correctly .. Could you pls help me where iam wrong....

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim str As String
  3. ftp_Date = Format(Date, "yyyymmdd")
  4. str = "D:\Daily FXPCA Trade Report\" & ftp_Date
  5. MsgBox str
  6. MkDir str
  7.  
May 18 '09 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,287
I've used this successfully:
Expand|Select|Wrap|Line Numbers
  1. Dim fso As Object
  2. Dim str As String
  3. str = ...
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. If Not fso.FolderExists(str) Then
  6.   fso.CreateFolder(str)
  7. End If
May 18 '09 #2

NeoPa
Expert Mod 15k+
P: 31,707
It doesn't seem too wrong to me :S

Can you check that the string is all spelt correctly (no typos) and that the parent folder exists already. Lastly, check the permissions of the parent folder (Can you create such a subfolder manually?).
May 18 '09 #3

ADezii
Expert 5K+
P: 8,679
This appears to be a case where you may wish to incorporate a simple Error Trap into the coding, to more clearly indicate any Errors which may occur, as in:
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Err_FolderCreation
  2. Dim str As String
  3. Dim ftp_Date As Variant
  4. Const conPATH_FILE_ACCESS_ERROR = 75
  5.  
  6. ftp_Date = Format(Date, "yyyymmdd")
  7. str = "D:\Daily FXPCA Trade Report\" & ftp_Date
  8.  
  9. MkDir str
  10.  
  11. MsgBox "The following Path, " & str & ", has successfully been created!", _
  12.         vbInformation, "Path Created"
  13.  
  14. Exit_FolderCreation:
  15.   Exit Sub
  16.  
  17. Err_FolderCreation:
  18.   If Err.Number = conPATH_FILE_ACCESS_ERROR Then     'The Folder already exists/Network Error
  19.     MsgBox "The following Path, " & str & ", already exists or there was an Error " & _
  20.            "accessing it!", vbExclamation, "Path/File Access Error"
  21.   Else
  22.     MsgBox Err.Description, vbExclamation, "Error Creating " & str
  23.   End If
  24.     Resume Exit_FolderCreation
May 19 '09 #4

P: 36
Thanks ADeZii,

It worked

Thanks a lot....
May 19 '09 #5

NeoPa
Expert Mod 15k+
P: 31,707
Perhaps you could tell us what you found the problem to be in the end?
May 19 '09 #6

ADezii
Expert 5K+
P: 8,679
@harshakusam
You are quite welcome. I'll repeat what NeoPa has already asked, what exactly was the problem?
May 19 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.