FileCopy Statement Example
This example uses the FileCopy statement to copy one file to another. For purposes of this example, assume that SRCFILE is a file containing some data.
Thanks a lot RhinoBull
but it didnt work, I have chosed the file to be copied and the distination and then i pressed copy. a message box "files done" appeared but no copy at that distination!!!!
I want to provide a backup option in my VB6 application, to copy the database to a pen drive. I tried the following code
Dim sourcefile,Destinationfile as string
Sourcefile=App.Path & "\HHA.mdb"
Destinationfile="TxtDrive.text" & "\HHA.mdb"
Filecopy Sourcefile,Destinationfile
*****************
It did not work."Permission denied" message is displayed.(App.Path->C:\My documents\HHA\HHA.mdb and destination->K:\HHA.mdb Please help me.
Are you sure the Folder "C:\My documents\HHA" exists?............
and your variable "sourcefile" is not a string......
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
For health reasons i try to avoid reading unformatted Code
"Permission denied" errors usually means your source HHA.mdb is opened by an ADO/DAO connection already and cannot be accessed before all connections to it from ADO/DAO are closed.
You cannot backup a "live" JET database that is currently in use or risk getting a corrupted copy of the data.
Yep that is definitely an invalid path. Unless of course you have a folder in your current folder named txtDrive.txt To get what is in the text box remove the quotes surrounding TxtDrive.text
Perhaps it's retyped in the text area of the forum with some obfuscation in mind because the original code contains confidental variable names and/or DB filenames. . .
Looking again I see the error message shows what may be a valid path. In that case it could be running into permissions issues. Root folders are protected and may deny requests to copy files there. Try using a folder on the target drive as your target.
Option Explicit
Private Sub Main()
Const ssfPERSONAL = 5
With CreateObject("Shell.Application")
MsgBox .NameSpace(ssfPERSONAL).Self.Path & "\HHA\HHA.mdb"
End With
End Sub
Wasn't this "C:\Users\username\Documents" even as far back as NT 4.0? Or at least since Vista?
I think the \User folder was introduced with Vista. Nt, 2000 and XP used a folder named Documents and Settings and the my documents folder was a sub folder within.
Of course there is no reason you could not create a folder off the root named My Documents.
I use ADO to connect. I understand the problem is "Permission" To copy from C Drive . But how can I overcome it.Suppose I install the application in some other computer,most probably the application and the database file will be in C Drive.There also this error message will be displayed and the application will be collapsed. The what is a solution. Any idea?
Once again Please mind, I am very new to programming, and have only little knowledge about computers.
I use ADO to connect. I understand the problem is "Permission" To copy from C Drive .
If you put your database on D: drive you will get "permission denied" too. It doesn't matter if it's on C: drive or on D: drive. You will get "permission denied" if your database is on whatever drive. So this is not the root cause of your problem.
You can prevent "permission denied" errors by closing every open ADO connection to your database. So to prevent read permission errors while copying your database file you have to first close every ADO connection that might lock portions of this database file so that FileCopy can succeed.
Dear WQWETO ,
I have done it.Closed all database files before copying,But still the same result.Will you put the code for closing the ADO connection,If only I am wrong in my code.
Thanks
Dear WQWETO ,
I have done it.Closed all database files before copying,But still the same result.Will you put the code for closing the ADO connection,If only I am wrong in my code.
Thanks
Try copying the .mdb file *before* opening the first connection to the database by calling FileCopy immediately before your conn.Open statement just for testing purposes so to be sure there are no open ADODB connections oustanding when FileCopy fails.
Closing all ADODB connections might not be that simple task depending on how you have your Data Access Layer structured. If you have server-side recordsets or ADODC controls littered across application forms this might even be mission impossible.
So it seems copying through programme is imposible. Then any other idea for copying the database file ,in case any thing happens to the computer of the user. Mind, it should be easy for a person who has little knowledge about computer.