?
Solved

Delete file from VBA with Permissions

Posted on 2008-02-01
7
Medium Priority
?
1,654 Views
Last Modified: 2008-03-06
Hi Guys,

I am having trouble deleting a files through VBA that have permissions (I.e they are open). How can i delete a file that is open?

I have an api call that i use for copying, that will overwrite any file open or not, i want the same affect just without copying a new file there. I have tried using FileSystemObject and the standard "Kill" and neither have any other options to delete whether it is open or not.

Thanks
0
Comment
Question by:Live4Surf
7 Comments
 
LVL 12

Expert Comment

by:James Elliott
ID: 20798026
You have an API that will overwrite an open file? Can i see it? To my knowledge, an open file is an open file and cannot be overwritten, unless the memory block is accessed directly.

Jell

0
 

Author Comment

by:Live4Surf
ID: 20798109
Ok Bascially, I have an update function on my access project. When the version  changes, the application will automatically update. Now doing this inside one program has cause i right pain in the backside, but i managed to do it using this Api:

Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
                   (ByVal lpExistingFileName As String, _
                   ByVal lpNewFileName As String, _
                   ByVal bFailIfExists As Long) As Long

and simply just:
     lngResult = apiCopyFile(strSourceFile, strDestFile, False)

This works perfectly, it finds the update file, and the running application gets overwritten, launches the new one and closes itself for good.

Cheers
0
 
LVL 12

Expert Comment

by:James Elliott
ID: 20798183
Private Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long


This is the only DeleteFile I could find, but as you notice, there is no switch to allow for continuation if the file exists. I suspect that it's not possible I'm affraid.

Jell

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 85
ID: 20798194
When you say "when the version changes", do you mean that you are updating your Access FE with a new one? If so, the easiest way is to just shell out to a new process and do the copy/paste there ... you can do this with either a small VB or Access app. I can't say that I'd EVER recommend you kill a running Access application just to do version changes ...
0
 
LVL 77

Expert Comment

by:peter57r
ID: 20798208
'This works perfectly'
..so you no longer need this Q answered - is that correct?
0
 

Author Comment

by:Live4Surf
ID: 20798326
No, the copying function works perfectly.

I just need the capability to be able to delete a file that is open and running. This is not for the update module,  as the copyapi works that a treat. But as i am not copying any files - it is a bit usless in this case.

Any other suggestions would be much appreciated.

@LSMConsulting:
You are not going to like this as an excuse, but we have a tight IT department, who dont quite understand programs properly. But they will not allow Exe's on our server, for some reason MDB/E's are much safer? Pfft, it gets on my nerves as it is. And yes before you ask it will be possible to to create the same effect in a MDB - but m,y updating works perfectly.The version changes, my FE version copys over the new version on top of itself (after closing all of its references), opens itself again and then closes the  other running version.

But it is possible to delete without having a "Permission Denied" error?

Regards
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 375 total points
ID: 20802168
Hi, this is in VBScript, but if you add a reference to Microsoft Scripting Runtime it should work, but you'd have to know the name of the server the file physically resides on.  If it's the local computer, just set strComputer = "."

What it should do is close an open file from a server....needs admin rights though.....

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23123980.html

Regards,

Rob.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

607 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