Hye again ,
I have problem to get Backup file .my code is bellow

Dim strB As String
'On Error Resume Next
strB = "D:\backup\db" & Date$ & ".mdb"
        FileCopy "C:\Database\MyDb.mdb", strB
    MsgBox "Backup Complete!!"

I always receive Run-time error '70' "Permission denied"
please help me

Dani AI

Generated

Quick summary tied to the replies: the Run-time error 70 on backup is almost always a filesystem/name/lock issue (see and ), and the “out-of-sequence / duplicate PK” you see after restore is an AutoNumber / sorting problem rather than lost data (related to ’s FSO idea but needs a safer filename and post-import fix).

Common causes and fixes

  • Illegal filename pieces: using Date$ in a filename frequently inserts slashes or other characters that Windows disallows; build a timestamped name composed only of safe characters (digits, underscore, hyphen). See Microsoft file-name rules. (learn.microsoft.com)
  • Locked/permission error: FileCopy (and FSO.CopyFile) will raise error 70 if the source or destination is locked/open or the destination is write-protected. Always ensure the DB is not open exclusively and that the account has write rights. (stackoverflow.com)

Safer backup pattern (example)

  • create a safe filename, ensure the folder exists, copy the file to a temp name, compact the temp copy and then rename it — that avoids copying a live file into a broken backup:
    
    Dim src As String, tmp As String, dest As String, folder As String
    folder = "D:\backup"
    If Dir(folder, vbDirectory) = "" Then MkDir folder
    src = "C:\Database\MyDb.mdb"
    tmp = folder & "\tmp_backup.mdb"
    dest = folder & "\db_" & Format(Now, "yyyy-mm-dd_hh-nn-ss") & ".mdb"

FileCopy src, tmp ' copy first (check source exists)
DBEngine.CompactDatabase tmp, dest ' compact the copy into final name
Kill tmp

Copy-to-temp + compact is a common, robust approach. ([access-programmers.co.uk](https://www.access-programmers.co.uk/forums/threads/can-i-do-this-in-vba.302944/?utm_source=openai))

Restore / AutoNumber notes
- DataReport order: reports don’t guarantee row order unless the RecordSource/query includes ORDER BY ItemID (or set the report’s sort). Sorting fixes the “wrong order” display.
- Duplicate PKs: AutoNumber can get “out of sync” if you imported or manually set ID values. Two safe fixes:
  1) If you can empty the table, reseed the counter: run a DDL reseed (via ADO) like:

CurrentProject.Connection.Execute _
"ALTER TABLE YourTable ALTER COLUMN ItemID COUNTER(1,1)"


(works when table is empty or the seed you set is greater than the max existing value). ([stackoverflow.com](https://stackoverflow.com/questions/20738596/how-to-reset-an-access-tables-autonumber-field-it-didnt-start-from-1?utm_source=openai))
  2) If you must keep existing IDs, create a new table (AutoNumber column) and append the old rows without the ID so Access assigns new sequential numbers.
- Design note: AutoNumber is for uniqueness, not for guaranteed human-friendly sequential numbering — if a strict sequence is required, maintain a separate numeric field and control it with DMax or transactional code. ([stackoverflow.com](https://stackoverflow.com/questions/13865579/access-autonumber-sequence-changed-after-compact-repair?utm_source=openai))

Cautions: always backup before altering table definitions, close any open DAO/ADO connections before copying, and test the reseed on a copy of the database first.

Recommended Answers

All 6 Replies

the error message is self explanatory

the what is solution?Please guide me. dear Das.

check if the path is proper (properly check for that date part in your path).

also check if any file already exists in the location by the same name.

how to make a restore file .I have already Data in MS Access i want to restore in Dababase.But i got proble.there are 256 records.When i got report in datareport these records are not arranged in sequence for example
first row is
Item ID - Item Name - Item Price
1. Juice 45.00 Rs
2. Pepsi 30.00 Rs
55. Cock 20.00 RS
290. Water 40.00 Rs
23. Milk 50.00 Rs

and so on.
all records are there but without sequence.
according to this example when i want to enter new record projects auto generate 24th ID.when i save this record. i got Primary Key Duplicate Error.
What have to do.?

I always receive Run-time error '70' "Permission denied"

Your database currently used. Close All connection before copying it.

first goto Project > Refernce from the menu bar. i the dialogue box that appears check the Windows Script Host Object Model. then use this code to copy;

Dim strB As String
Dim fs As FileSystemObject
Set fs = CreateObject("scripting.filesystemobject")

strB = "D:\backup\db" & Date$ & ".mdb"

If (fs.FolderExists("D:\backup")) Then
    fs.CopyFile "C:\Database\MyDb.mdb", strB, True
    MsgBox "Backup Complete!!" 
else
    MsgBox "Folder doesn't Exist"
End If
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.