Solved

Moving and Deleting files in Access 2007

Posted on 2009-03-30
6
188 Views
Last Modified: 2013-11-27
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
Comment
Question by:DMC14319
  • 3
  • 3
6 Comments
 
LVL 75
ID: 24024009
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
 

Author Comment

by:DMC14319
ID: 24024055
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
 
LVL 75
ID: 24024110
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:DMC14319
ID: 24024154
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
 
LVL 75
ID: 24024270
" 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
 

Accepted Solution

by:
DMC14319 earned 0 total points
ID: 24043961
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question