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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error capture for FileCopy statement 1

Status
Not open for further replies.

08211987

Programmer
Apr 20, 2012
187
US
HI!
I have this code below that I have referenced in another thread but that thread was not trying to solve what I am trying to resolve in this thread.
The other thread is What I need to resolve is in this code below is that I am setting up to export a query to an excel template that is already formatted. In the FileCopy statement below I am copying the template to the variable where the query should be exported to. If by chance the user has already opened that spreadsheet and didn't close it and runs the process that will redo this export it gives an error "Run-time 70 Permission denied" because the user already has the file open. How can I capture the error for the FileCopy so that I can give the user a friendly msgbox to say "the file is already open, either close it or use it instead"? And then exit the Sub?

Sub GTINs_Already_Synched_Submitted_by_Vendor()
DoCmd.SetWarnings False
template_file = "\\msfs05.lowes.com\data1\share\MDCM_Reports\Product_Information\PI Item Setup Tracker\Templates\GTINs Already Synched Submitted by Vendor.xlsm" '
report_file = "C:\PI_Edgenet_Reports\GTINs Already Synched Submitted by Vendor.xlsm"
sheet_name = "GTINs Already Synched Submitte"
FileCopy template_file, report_file
DoCmd.TransferSpreadsheet acOutputQuery, 10, "qry_tbl_Vendor_Email_From_Edgenet_Synched_History", report_file, False, "Data1"
Export_Report_For_All
End Sub
Appreciate anyone's assistance!
Thanks,
CF
 
It would be nice to see your code as [tt]code[/tt] with TGML tags....

Code:
Sub GTINs_Already_Synched_Submitted_by_Vendor()
[blue]
On eror GoTo MyErroHandler
[/blue]
 DoCmd.SetWarnings False
 template_file = "\\msfs05.lowes.com\data1\share\MDCM_Reports\Product_Information\PI Item Setup Tracker\Templates\GTINs Already Synched Submitted by Vendor.xlsm" '
 report_file = "C:\PI_Edgenet_Reports\GTINs Already Synched Submitted by Vendor.xlsm"
 sheet_name = "GTINs Already Synched Submitte"
FileCopy template_file, report_file
 DoCmd.TransferSpreadsheet acOutputQuery, 10, "qry_tbl_Vendor_Email_From_Edgenet_Synched_History", report_file, False, "Data1"
 Export_Report_For_All
[blue]
Exit Sub
MyErroHandler:

If Err.Number = 70 Then
    MsgBox "Something Happenned Here..."
    Exit Sub
End If
[/blue]
 End Sub

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Thanks, I'll give it a try and let you know. Here's a star for now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top