Backups Automatically

  • Thread starter Thread starter dbalorenzini
  • Start date Start date
D

dbalorenzini

I have a customized ribbon on which I want to add a button that allows the
user to back up and compact the database. I know how to add buttons to the
ribbon but what commands would I use?
 
Here's the only way I know how to do it. First create a public function in a
module that will have VBA code that will do the backup, then create a macro
that uses the RunCode command, with the name of your backup function as the
function name for RunCode. Your button would point to the macro. You need to
include brackets when you specify the function name, e.g. if your backup
function is called CreateBackup then for Function Name in the macro you would
have CreateBackup(). I don't know of any Access commands that will create a
backup - pretty sure you have to do this with VBA. Here's a sample of what
the funciton would look like:

Public Function CreateBackup() as Boolean

Dim FSO As FileSystemObject

Set FSO = New FileSystemObject

If FSO.FileExists(DBFileName) Then
FSO.CopyFile dataFileName, backupFileName, True
CreateBackup = True
Else
CreateBackup = False
Msgbox "The file you are trying to back up does not exist."
End If

End FUnction

You need to specify the file names for your file to be backed up and the
file name you want for your backup. You'd also need to add 'standard' error
handling (an On Error GoTo... or however you handle your errors).

I think for the file system objects you need to add a reference (In VBA,
goto Tools, References). I think you need to have a reference for Windows
Script Host Object Model. Hope this helps.

Jim B
 
You also want to include this statement at the end

Set FSO = nothing

I had DBFileName in one place and dataFileName in another, but those would
both just refer to the file name of the database you're backing up. The TRUE
argument tells it to overwrite the backup file if that file name already
exists.
 
dbalorenzini said:
I have a customized ribbon on which I want to add a button that allows the
user to back up and compact the database. I know how to add buttons to the
ribbon but what commands would I use?

When the user exits the FE attempt to rename the backend MDB
preferably with todays date in the name in yyyy-mm-dd format. Ensure
you close all bound forms, including hidden forms, and reports before
doing this. If you get an error message, oops, its busy so don't
bother. If it is successful then compact it back.

See my Backup, do you trust the users or sysadmins? tips page for more
info.
http://www.granite.ab.ca/access/backup.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Back
Top