PDA

View Full Version : Creating / Checking Folder help



JayM
01-18-2006, 05:14 AM
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 ThenHandler: 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

mdmackillop
01-18-2006, 05:52 AM
Hi Jay,
Welcome to VBAX
Have a look at these items
http://www.vbaexpress.com/kb/getarticle.php?kb_id=559
http://www.vbaexpress.com/kb/getarticle.php?kb_id=634
Regards
MD

BTW. If you select your code and click the VBA button, it formats as above, making it more readable.

JayM
01-18-2006, 06:26 AM
For your help and the tip re the code:thumb .

I will try the examples out but no doubt I will be back for help on something else before long.