Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File copy

Status
Not open for further replies.

MAVTCR

Programmer
Feb 23, 2021
28
IN
I want to give an option for backup in my vb6 application .The database file has to be copied to a pen drive. I am using windows XP. i give below my code

Dim sourcefile, destination file as string
sourcefile = App.Path &"\HHA.mdb"
Destinationfile = "TxtDrive.text" & "\HHA.mdb"
Filecopy Sourcefile,Destinationfile

******* The above code did not work . "Permission denied" message is displayed. Please help me
Here the App Path -> C:\My documents\HHA\HHA.mdb
Destination -> K:\HHA.mdb
 
>Destination -> K:\HHA.mdb

Well, no - you're code shown here sets the destination to: [tt]TxtDrive.text\HHA.mdb[/tt]

If TxtDrive.text is a text file containing the drive letter, then you need to write code to open it and read the contents

If it is a variable, then it shouldn't be in quotes
 
If [tt]TxtDrive[/tt] is a TextBox containing the destination path, then try:

Code:
Dim sourcefile [red]As String[/red], destinationfile As String

sourcefile = App.Path & "\HHA.mdb"
destinationfile = TxtDrive.Text & "\HHA.mdb"

MsgBox "Copy File: " & sourcefile & " to: " & destinationfile
FileCopy sourcefile, destinationfile

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I have tried as you told.
But still the error message- Runtime error-70 Permission denied.
 
Andy's code specifically out puts the parsed sourcefile and destination file in a messagebox. Are you 100% happy they are correct?
 
Permission denied.- are you sure you can use this destination? For more info, see this

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Is the file still open or locked? You can try to copy using Microsoft Scripting Runtime library (need a reference or for late binding [tt]Set fso=CreateObject("Scripting.FileSystemObject")[/tt]):
Code:
Dim strFileSource As String, strFileTarget As String
Dim fso As Scripting.FileSystemObject

strFileSource = App.Path & "\HHA.mdb" [COLOR=#4E9A06]' test if "C:\My documents\HHA\HHA.mdb"[/color]
strFileTarget = TxtDrive.Text & "\HHA.mdb" [COLOR=#4E9A06]' test if " K:\HHA.mdb"[/color]
Set fso = New Scripting.FileSystemObject
fso.CopyFile strFileSource, strFileTarget


combo
 
I changed my code for testing:
Sourcefile="K:\HHA\Support\HHA.mdb"
This worked well.
Again I worked on the below code
Sourcefile="C:\My Documents\HHA\HHA.mdb"

Now again the same error message "Permission Denied"
ie. From C: drive copying is not allowed. How can I overcome this?
 
Check your permissions (Properties > Security) on

C:\My Documents\HHA

.
 
So, it looks to me there is nothing wrong with your code or your syntax.
But "Permission Denied" error points to, well... Permissions [upsidedown]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I understand the problem is "permission".But how can I overcome.Suppose my application is installed in some other's computer, most probably the application and the database file will be in the C drive. There also this error message may arise, and the application may collapse.Then what is the solution. Any idea.

Once again ,please mind , I am a beginner in programming and have only little knowledge of computer.
 
Can you make a copy of your file to the same location, like this:

Code:
Dim sourcefile As String, destinationfile As String

sourcefile = App.Path & "\HHA.mdb"
destinationfile = [red]App.Path[/red] & "\[red]CopyOf[/red]HHA.mdb"

MsgBox "Copy File: " & sourcefile & " to: " & destinationfile
FileCopy sourcefile, destinationfile

If yes, no permission errors, that would mean you cannot write to other places for whatever reason.
If no, you get the permission error anyway, then your sourcefile may be locked by Access and that may be the reason you cannot copy it.

"what is the solution" - Error trapping, and display a message to the user of what happened and how to solve it.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
So copying through program is not possible, I think. Is there any idea to help the user to copy the database files to save the data in case any thing happens to the computer. Mind any person having little knowledge,should be able to do it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top