Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command button to insert a folder-need help with error msg.

Status
Not open for further replies.

ajaeger

Technical User
Feb 6, 2003
201
0
0
US
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
 
Hi, This is a bit of a fudge but you could hide a second command button under the one you already have. On the click event you could pass the focus to the second command button and hide the first. The second button could then just give a message like "Folder already created".

All the best, Jobo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top