Is it possible to take a backup of an accessdatabase via VBcode? The user wants that it is possible to take a backup of his data on a floppy. And I haven't got a clue how to start, thx
Step 1 - make sure everyone's out of the database
Step 2 - copy the *.mdb file to the backup medium (ZIP it, or whatever)
Step 3 - tell everyone it's OK to get back into the app
You can use the above technique, but not safely. If someone other than your user is actively writing to the MSAccess database when the file copy happens, the backup is made with an unknown state. If you had some way in your code to signal other users not to make insert/update statements (network signalling, a "IsLocked" column in a table, etc) this would work.
Tom,
When the user clicks to backup the database, close the database then try and open for exclusive access. If you get an error then someone else has it open. You could at that point place a message within the database and have a timer to poll for any messages within your app which could then ask all users to log off as a backup is required.
Private Sub mnuBackupItem_Click()
Dim SourceFile, DestinationFile, Default
Default = A:\backup.mdb"
SourceFile = "C:\original folder\original.mdb"
Prompt$ = "Would you like to make a backup copy of the database?"
reply = MsgBox(Prompt$, vbOKCancel, SourceFile)
If reply = vbOK Then
DestinationFile = InputBox$("Enter the pathname for the backup copy.", "File Backup", Default)
If DestinationFile <> "" Then FileCopy SourceFile, DestinationFile
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.