J
JayM
Hi
I have a form (frmFolderCreation) with a combobox (cboDept) and a text field
(txtMyFolderName).
The idea of this is to create folders automatically dependent upon which
department users are in and once it creates the folder will then copy some
standard folders into it.
My problem is, having written the code, with lots of help from the internet
because I am a novice at this stuff, if the folder already exists it gives me
a message to say so but then closes the form - how can I stop the form
closing in this instance so that the user can type another name but close if
the folder is just created.
My code is :
Private Sub cmdOK_Click()
Dim MyFilePath As String
Dim strMsg As String
Select Case cboDept.Value
'Stourport and Worcester have the same path
'so if cboDept.Value is either one, we treat
'with the same Case conditions
Case "Stourport", "Worcester"
MyFilePath = "w:\data\_Clients\"
Case "Kidderminster - Business"
MyFilePath = "w:\data\Business\_Clients\"
Case "Kidderminster - Civil"
MyFilePath = "w:\data\Business\_Clients\"
Case "Kidderminster - Crime"
MyFilePath = "w:\data\Crime\_Clients\"
Case "Kidderminster - Family"
MyFilePath = "w:\data\Family\_Clients\"
Case "Kidderminster - Probate"
MyFilePath = "w:\data\Probate\_Clients\"
Case "Kidderminster - Property"
MyFilePath = "w:\data\Property\_Clients\"
Case Else
strMsg = "Unexpected Selection in cboDept."
End Select
Dim fso
Dim fol As String
Dim sfol As String
fol = MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName
sfol = MyFilePath & "\_DUMMY FOLDER"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
Else
MsgBox fol & " already exists!", vbExclamation, "Folder Exists"
End If
Unload frmFolderCreation
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbExclamation, "Invalid
Source"
ElseIf Not fso.FolderExists(fol) Then
MsgBox fol & " is not a valid folder/path.", vbExclamation, "Invalid
Destination"
Else
fso.CopyFolder sfol, fol
End If
If Err.Number = 53 Then MsgBox "File Not Found"
End Sub
Any help with this would be very much appreciated.
JayM
I have a form (frmFolderCreation) with a combobox (cboDept) and a text field
(txtMyFolderName).
The idea of this is to create folders automatically dependent upon which
department users are in and once it creates the folder will then copy some
standard folders into it.
My problem is, having written the code, with lots of help from the internet
because I am a novice at this stuff, if the folder already exists it gives me
a message to say so but then closes the form - how can I stop the form
closing in this instance so that the user can type another name but close if
the folder is just created.
My code is :
Private Sub cmdOK_Click()
Dim MyFilePath As String
Dim strMsg As String
Select Case cboDept.Value
'Stourport and Worcester have the same path
'so if cboDept.Value is either one, we treat
'with the same Case conditions
Case "Stourport", "Worcester"
MyFilePath = "w:\data\_Clients\"
Case "Kidderminster - Business"
MyFilePath = "w:\data\Business\_Clients\"
Case "Kidderminster - Civil"
MyFilePath = "w:\data\Business\_Clients\"
Case "Kidderminster - Crime"
MyFilePath = "w:\data\Crime\_Clients\"
Case "Kidderminster - Family"
MyFilePath = "w:\data\Family\_Clients\"
Case "Kidderminster - Probate"
MyFilePath = "w:\data\Probate\_Clients\"
Case "Kidderminster - Property"
MyFilePath = "w:\data\Property\_Clients\"
Case Else
strMsg = "Unexpected Selection in cboDept."
End Select
Dim fso
Dim fol As String
Dim sfol As String
fol = MyFilePath & Left(txtMyFolderName, 1) & "\" & txtMyFolderName
sfol = MyFilePath & "\_DUMMY FOLDER"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
Else
MsgBox fol & " already exists!", vbExclamation, "Folder Exists"
End If
Unload frmFolderCreation
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbExclamation, "Invalid
Source"
ElseIf Not fso.FolderExists(fol) Then
MsgBox fol & " is not a valid folder/path.", vbExclamation, "Invalid
Destination"
Else
fso.CopyFolder sfol, fol
End If
If Err.Number = 53 Then MsgBox "File Not Found"
End Sub
Any help with this would be very much appreciated.
JayM