INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Error capture for FileCopy statement

Error capture for FileCopy statement

(OP)
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 http://www.tek-tips.com/viewthread.cfm?qid=1775583
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

RE: Error capture for FileCopy statement

It would be nice to see your code as code with TGML tags....

CODE

Sub GTINs_Already_Synched_Submitted_by_Vendor()

On eror GoTo MyErroHandler

 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

Exit Sub
MyErroHandler:

If Err.Number = 70 Then
    MsgBox "Something Happenned Here..."
    Exit Sub
End If

 End Sub 

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Error capture for FileCopy statement

(OP)
Thanks, I'll give it a try and let you know. Here's a star for now!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close