• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Moving and Deleting files in Access 2007

I have a form which I am viewing pdf files in a web browser.  I have 2 text boxes on the form which hold the current filename and path and another which will hold the newname and path.  Using the FileSystemObject I want to copy the file to the new location and then delete the source file.  The problem is that because the source file is being viewing in the web browser it throws a run-time 70, Permission Denied error.  Pointing the browser to something else i.e. another pdf or webpage before fso.deletefile  does not work to release the current file for deletion.  Any suggestions?
Forms!frmMyForm!WebBrowser.Navigate2(CurrentFilePath)
fso.CopyFile(CurrentFilePath, NewFilePath)
If fso.FileExists(NewFilePath) then
Forms!frmMyForm!WebBrowser.Navigate2(NewFilePath)
DoEvents
fso.DeleteFile(CurrentFilePath)
End If

Open in new window

0
DMC14319
Asked:
DMC14319
  • 3
  • 3
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
FSO CopyFile should copy the file even if it is open ... it does for Access MDB's - because I just finished an entire app for automated backup based on the FSO.

Are you sure the error is not occurring on
fso.DeleteFile(CurrentFilePath)

?

mx
0
 
DMC14319Author Commented:
Yes the error is occuring while attempting to delete the file.  I have tried a number of things to slow or halt the code to make sure the browser unloads the file before the fso.deletefile but with no luck.  I have explored the "navigatecomplete2" without any luck also.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Humm.  Well, I had a similar issue in part of the backup routine - during the Compact and Repair process ... wherein I was using Shell to execute an Access command line to do the C&R - in a loop (about 20 mdb's). BUT ... I did not want to start the next C&R until the previous one completed.  So, I ended up using ShellWait - found here:

http://www.mvps.org/access/api/api0004.htm

That immediately solved that problem.  Maybe there is some way to use this to determine when the copy process completes.  Or, what about killing the browser task first?

I don't completely get what you are trying to do?  The browser has a PDF open - but you are trying to  copy it to a new location?

mx
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
DMC14319Author Commented:
Yes the users need to view the pdf first to make sure they have to correct file before moving it to a new location.  Once the file has been renamed and copied to a new location they need to delete the original file.  I will look into killing the browser task.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
" I will look into killing the browser task."

ok ... so, you have the browser control on a form, right?

I'm thinking then that you could execute something like

' some code

Set oBrowserControl = Nothing   ' set the browser instance to nothing

' more code

oBrowserControl  would be the name of the object variable assigned to the browser control.

BUT ... I don't know if that would really 'kill' the instance of the browser in Task Manager - easy to try however.   Plus ... wouldn't this be annoying to the user ?

mx
0
 
DMC14319Author Commented:
Couldn't find a suitable solution for this problem.  The workaround was to make a local temporary copy of the file and viewing the temp copy in the browser control.  Therefore the file system object was free to move, copy or delete the source file without locking issues.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now