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
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