I would like to enable the user of my app. to backup the Access (.mdb) database file to floppy each day (it's pretty small for now). Is there an API call or built in function to do this? Thank you in advance.
Printable View
I would like to enable the user of my app. to backup the Access (.mdb) database file to floppy each day (it's pretty small for now). Is there an API call or built in function to do this? Thank you in advance.
1. You can use FileCopy function.
2. You can use Shell function to run some archive programs (winzip, pkzip, ...) with parameters that will zip file and copy it to floppy!
Ermin
...or you can drop common dialog control on your form and then use DAO and a modified version of the following code to ask the user where to place the backup copy and then create the backup copy via DatabaseCompact which has the advantage of creating the smallest possible file.
To use the above you will want to delete the g_dbRWTU.CloseCode:Public Function CreateDB() As Boolean
'***************************************************************************
'Purpose: Create the extract database via CompactDatabase
'Inputs: None
'Outputs: None
'***************************************************************************
Dim wrkDefault As Workspace
frmExtract.dlgMDB.CancelError = True
frmExtract.dlgMDB.DefaultExt = "MDB"
frmExtract.dlgMDB.Filter = "Test Case Database Files(*.MDB)|*.MDB"
On Error Resume Next
frmExtract.dlgMDB.Flags = cdlOFNOverwritePrompt Or cdlOFNExtensionDifferent Or cdlOFNPathMustExist
frmExtract.dlgMDB.Action = 2
If Err = 32755 Then 'Cancel
Err.Clear
CreateDB = False
Exit Function
End If
On Error GoTo ErrorRoutine
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of
' the new database.
If Dir(frmExtract.dlgMDB.FileName) <> "" Then
Kill frmExtract.dlgMDB.FileName
End If
g_dbRWTU.Close
DBEngine.CompactDatabase "c:\rwt\data\rwtu.mdb", frmExtract.dlgMDB.FileName
CreateDB = True
Exit Function
ErrorRoutine:
CreateDB = False
DisplayError "CreateDB", "Error", vbCritical
End Function
line, change the hard-coded database name in the CompactDatabase line, and change the ErrorRoutine to suit yourself.
from ermingut, to use the pkzip utility with the
Shell function, an example is shown below:
ret = Shell("c:\utils\pkzip a:\BkUp c:\MyMdb\MyMdb.mdb")
Caution: vb or vba does not wait for the Shell command
to finish its process (i.e. it goes straight
to the next program line)
hope this helps...:)
Thanks to all who commented. Very useful information.