Solved

Moving and Deleting files in Access 2007

Posted on 2009-03-30
6
181 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now