Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Folders using VB in MS Access

Status
Not open for further replies.

gibblin

Technical User
Oct 9, 2003
27
GB
This will probably be an easy one for someone.........

I simply want to know the code for creating a folder in a drive, where the name of the folder is the current month and year.

any help would be greatly appreciated.
 
Take a look at the MkDir, Format and Date functions.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi Gibblin,
Try this out:

Private Sub Command3_Click()

Dim strCurrM As String, strCurrY As String
On Error GoTo Err_Exit

strCurrM = Format(Date, "mmmm")
strCurrY = Format(Date, "yyyy")

MkDir "C:\" & strCurrM & " " & strCurrY

Err_Exit:
MsgBox Err.Description

End Sub

Peace,
me2you

 
Both of the above posts mention the MkDir which is the correct function.

Please keep in mind that MkDir can only create one directory at a time, and the parent of that directory must already exists. me2you's example creates the directory off the root of the C: drive which is correct, but if you try:
[tt]
MkDir "C:\sub1\sub2\sub3\sub4\YourDir"
[/tt]
Then the sub1, sub2, sub3, and sub4 directories must already exist. If they don't, then you will have to build the entire directory tree in order before you can make YourDir.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks everyone for your quick replies, haven't had chance yet to try it out. busy, busy, busy at work!
I'll reply back to how i get on.

cheers.
 
Another way for creating any directory, provided no permission issue:
Sub myCreateFolder(strPath)
Set fso = CreateObject("Scripting.FileSystemObject")
tmpArr = Split(strPath, "\")
tmpPath = tmpArr(0)
For i = 1 To UBound(tmpArr)
If Not fso.FolderExists(tmpPath) Then
fso.CreateFolder tmpPath
End If
tmpPath = tmpPath & "\" & tmpArr(i)
Next
Set fso = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks everyone, sorry about the delay in replying, but i got it working! much appreciated. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top