On my insert form, I have a command button to save the record and create a folder on the C drive named after the ID field. It works fine, except when the user click the button twice. Then they get an error message "Path/File access error" since the folder already exists and they are trying to re-create it.
I need to find a way to avoid an error message. Something like "save the record and create a folder if the folder does not already exist. If the folder does exist, just save the record."
The code I have behind the button is:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
'Save Record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'Insert Folder
Dim ReqID As String
ReqID = CStr(Me!RequestID)
If (Dir("c:\folders\" & ReqID)) = ReqID Then
intMsg = MsgBox("The folder exists"
This line above is never true, therefore the logic always goes to the 'else' statement. I think this is where I need to specify 'if a folder named ReqID exists, then skip the MkDir.
Else
MkDir ("c:\folders\" & ReqID)
End If
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
I need to find a way to avoid an error message. Something like "save the record and create a folder if the folder does not already exist. If the folder does exist, just save the record."
The code I have behind the button is:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
'Save Record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'Insert Folder
Dim ReqID As String
ReqID = CStr(Me!RequestID)
If (Dir("c:\folders\" & ReqID)) = ReqID Then
intMsg = MsgBox("The folder exists"
This line above is never true, therefore the logic always goes to the 'else' statement. I think this is where I need to specify 'if a folder named ReqID exists, then skip the MkDir.
Else
MkDir ("c:\folders\" & ReqID)
End If
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub