|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File Copy Without ClosureDuring the course of a VB6 procedure a want to make a copy of an Access database, hopefully without closing it as seems to be required by FileCopy. I have noted that Windows Explorer has no trouble copying an open file. I have included the following code in the procedure largely copied from the Language Ref manual It halts on the last instruction with the message "Type Mismatch" Is there any way through this with this approach or should I resort to FileCopy Thanks in anticipation Roger Stenson Dim f, fs, s Dim CopyPath As String CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) & DatePart("m", Date) & DatePart("d", Date) & ".mdb" Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFile(DBPath) Set s = f.Copy(CopyPath) ---------- Roger Stenson wrote:
> During the course of a VB6 procedure a want to make a copy of an Access That would be true only if the process that has the file opened, did> database, hopefully without closing it as seems to be required by FileCopy. > I have noted that Windows Explorer has no trouble copying an open file. not open the file exclusively. > The Copy method of the file object does not return a value to my> Dim f, fs, s > > Dim CopyPath As String > > CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) & > DatePart("m", Date) & DatePart("d", Date) & ".mdb" > > Set fs = CreateObject("Scripting.FileSystemObject") > > Set f = fs.GetFile(DBPath) > > Set s = f.Copy(CopyPath) knowledge. What is s supposed to contain after the copy operation is complete? If you are using the FileSystemObject, why not use fs.CopyFile ?? VB's built in FileCopy method, according to the docs, throws an error if the file being copied is open. But as I alluded to earlier, if the process that has the file opened locked the file for reading by other processes, then you will not be able to copy it, regardless of the method you choose. Roger
This can be done using SHFileOperation API. This API will do lots of things like moving to the Recycle bin and showing the file copy/move/delete animation so it is best to work out which functions you need then write (or adapt someone elses) a wrapper to expose what you need. You will need to add some code to trap copy failures if the database is open with exclusive access. Examples can be found all over the net, but an obvious first port of call would be Randys site http://vbnet.mvps.org http://www.mvps.org/ is also a good jumping off place for all sorts of help. Regards Dave O. Show quoteHide quote "Roger Stenson" <r.sten***@paston.co.uk> wrote in message news:b9eYe.8613$1A.2021@newsfe1-gui.ntli.net... > Hi all > > During the course of a VB6 procedure a want to make a copy of an Access > database, hopefully without closing it as seems to be required by > FileCopy. I have noted that Windows Explorer has no trouble copying an > open file. > > > > I have included the following code in the procedure largely copied from > the Language Ref manual > > It halts on the last instruction with the message "Type Mismatch" > > Is there any way through this with this approach or should I resort to > FileCopy > > Thanks in anticipation > > > > Roger Stenson > > > > Dim f, fs, s > > Dim CopyPath As String > > CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) & > DatePart("m", Date) & DatePart("d", Date) & ".mdb" > > Set fs = CreateObject("Scripting.FileSystemObject") > > Set f = fs.GetFile(DBPath) > > Set s = f.Copy(CopyPath) > > ---------- > >
[VB6] Passing the variable value to the form?
Fluctuation of printer alignment Database and report question Newbie: How to extract year from a Date object VB6 : Attach Event Handlers to Dynamically Generated Controls How can i make sure msgbox problem List all jpg files from folder (loop problem) Random first random number delete |
|||||||||||||||||||||||