Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Creating Folders help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JayM - 18 Jan 2006 11:41 GMT
I have written the below code.  The code creates a folder dependent on the
information from a form.

That bit works fine but I can't get it to check whether the folder already
exists and if so prompt the user to change the name.  I have tried it with an
inputbox, message box and with another form.  

Any help would be greatly appreciated.

Private Sub cmdOK_Click()

Dim MyFilePath As String
Dim TestFolder
Dim TestAlphaFolder

If cboDept.Value = "Stourport" Then MyFilePath = "w:\data\_Clients\"
If cboDept.Value = "Worcester" Then MyFilePath = "w:\data\_Clients\"
If cboDept.Value = "Kidderminster - Business" Then _
   MyFilePath = "w:\data\Business\_Clients\"
If cboDept.Value = "Kidderminster - Civil" Then _
   MyFilePath = "w:\data\Business\_Clients\"
If cboDept.Value = "Kidderminster - Crime" Then _
   MyFilePath = "w:\data\Business\_Clients\"
If cboDept.Value = "Kidderminster - Family" Then _
   MyFilePath = "w:\data\Business\_Clients\"
If cboDept.Value = "Kidderminster - Probate" Then _
   MyFilePath = "w:\data\Business\_Clients\"
If cboDept.Value = "Kidderminster - Property" Then _
   MyFilePath = "w:\data\Business\_Clients\"

TestFolder = Dir(MyFilePath & txtMyFolderName) & "\"

'If TestAlphaFolder = Dir(MyFilePath & Left(txtMyFolderName, 1) & "\") Then
GoTo ClientFolders

If Len(TestFolder) = 0 Then
Handler:
   MkDir MyFilePath & Left(txtMyFolderName, 1) & "\"
'ClientFolders:
   MkDir MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName
   MkDir MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName &
"\Bills"
   MkDir MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName &
"\Documents"
   MkDir MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName &
"\Correspondence"
Else
   txtMyFolderName = MsgBox("File " & txtMyFolderName & " already exists" _
       & Chr(10) & Chr(10) & "Please type another folder name", vbOKOnly,
"File Exists")
End If

frmFolderCreation.Hide

End Sub
Kevin B - 18 Jan 2006 13:40 GMT
You can use the following formula, which returns a True/False result, to
determine if a folder exists or not:

Function DirExists(strPath As String) As Boolean
   
   DirExists = (Len(Dir(strPath, vbDirectory)) > 0)
   
End Function

Signature

Kevin Backmann

> I have written the below code.  The code creates a folder dependent on the
> information from a form.
[quoted text clipped - 51 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.