Friends, I met with a small problem please help me
I developed a small programme. When I exit from it I want to make a backup in another drive
I coded like this

  FileCopy "I:\My Documents\New Folder\Pebble.mdb", "D:\Pebble\Pebble.mdb"

Here the "Pebble.mdb" is my database in Drive "I". I want to copy it to Drive "D" on exiting. The code is under the click event of command button Exit.On running the programme I am getting the error message "Permission Denied" How can I solve?
And if I want to take a back up in my pendrive what coding should be?In my computer the pendrive is in K: While in some it is in H: How can I code the target drive common to all computers?
Please help me..

Dani AI

Generated

Two things cause the typical "Permission denied" when trying to back up an MDB at exit: the database file is still open/locked by the app (or by Access/another process), or Windows/UAC/NTFS blocks writing to the chosen target folder. 's FileCopy approach is fine in principle; 's "run as administrator" idea addresses only the second class of problem.

Close the DB engine/connection before attempting a copy. For ADODB close the connection and release the object; for DAO either Close the Database and Set it Nothing or use DAO's compact-as-backup which avoids copying an active file. Example patterns (showing the sequence, not the FileCopy form already in the thread):

' close ADODB connection
If Not gConn Is Nothing Then
  If gConn.State = 1 Then gConn.Close
  Set gConn = Nothing
End If

' copy using FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(destFolder) Then fso.CreateFolder destFolder
fso.CopyFile srcPath, destFolder & "\Pebble.mdb", True
Set fso = Nothing

Alternatively, when DAO is available the compact routine produces a safe backup (requires a DAO reference):

' compact to create a clean copy
DBEngine.CompactDatabase srcPath, dstPath

For USB/backups that can appear on different letters, enumerate removable drives and copy to the first ready one (or present a FolderBrowser/Common Dialog so the user selects the target). If "Run as administrator" isn’t visible, right‑click the compiled EXE (not the MDB or a shortcut) or set the EXE's Compatibility property; a more robust design is to write backups to a user-writable folder (Documents) or let the user choose the destination. Finally, trap Err 70 to distinguish "file in use" from "cannot write" and log or retry after closing resources.

Recommended Answers

All 6 Replies

Dim SourceFile, DestinationFile As String
SourceFile = "SRCFILE" ' Define source file name.
DestinationFile = "DESTFILE" ' Define target file name.
FileCopy(SourceFile, DestinationFile) ' Copy source to target

I tried the above code as follows

Dim SourceFile, DestinationFile As String
SourceFile = "C:\My Documents\New Folder\Pebble.mdb" 
DestinationFile = "D:\Pebble\Pebble.mdb" 
FileCopy SourceFile, DestinationFile 

On working, the following error message is shown :Permission denied.

I think the folder requires administrator permission to copy the files . Try with the folder in D drive . It might works !!!

Sorry.. What should I do.. I have little knowledge in this field...

I think the folder requires administrator permission to copy the files . Try with the folder in D drive

i think it can be solved by starting application with administrator rights. you can do that by running it as administrator.It can be simply find by right clciking on the application icon.

Sorry I am not getting on right clicking. On right clicking options like the following are listed.. Open,make,run ,MediaInfo,Open with,Send to,Copy,Delete,Rename,Cut etc. .. Administrator does not come to the picture.What can I do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.