Hello,
I need the procedure and/or code to add a command button to the Main Switchboard form, so the user click it and creates a full backup of the database in other folder, where the database name will have the date added to it.
I have tried different things, with no success... getting depress now!
if I press tools, database utilities, and backup database I'll get what I want, ... well I need to do the same, but using a command button.
(paramount will be if I can do the same without the user intervention, just checkind the date and if has been 7 days since the last backup, trigger a new one automatically)
many thanks in advance
Juan
The following code will Backup all Database Objects to a Folder specified by the Constant conPATH_TO_BKUPS (Line #3). You can change this if you wish, but be sure to add the Trailing Backslash since I did not test for this for the sake of brevity. The actual Back Up Database will be the Base Name of the Current Database minus the .mdb Extension, plus an Underscore (_), plus the Date formatted as mmddyyyy, plus .mdb. Each Backup will be unique only as far as a single Day is concerned and will DELETE a previous Backup for that Day should it exist. I intentionally placed the code in a Public Function where it can easily and directly be called from a Main Switchboard Item. Have fun, and if you have any questions, please feel free to ask. - Public Function fExportAllDBObjects()
-
On Error Resume Next
-
Const conPATH_TO_BKUPS As String = "C:\DB Backups\"
-
Dim strAbsoluteBkUpPath As String
-
Dim aob As AccessObject
-
Dim strDBName As String
-
Dim wrkSpace As Workspace
-
Dim dbBackup As Database
-
-
DoCmd.Hourglass True
-
-
'Retrive the Current Database Name only, strip out .mdb
-
strDBName = Replace(Mid$(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1), ".mdb", "")
-
-
'Make the Backup DB Name unique for each Date
-
strDBName = strDBName & "_" & Format$(Date, "mmddyyyy") & ".mdb"
-
-
strAbsoluteBkUpPath = conPATH_TO_BKUPS & strDBName
-
-
'If a Bacup already exists for this Date, then DELETTE it
-
If Dir$(strAbsoluteBkUpPath) <> "" Then
-
Kill strAbsoluteBkUpPath
-
End If
-
-
'Get Default Workspace.
-
Set wrkSpace = DBEngine.Workspaces(0)
-
-
'Create the Database
-
Set dbBackup = wrkSpace.CreateDatabase(strAbsoluteBkUpPath, dbLangGeneral)
-
-
'Export all Tables
-
For Each aob In CurrentData.AllTables
-
If Mid$(aob.Name, 2, 3) <> "Sys" Then 'Don't Export System Tables
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acTable, aob.Name, aob.Name
-
End If
-
Next
-
-
'Export all Queries
-
For Each aob In CurrentData.AllQueries
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acQuery, aob.Name, aob.Name
-
Next
-
-
'Export all Forms
-
For Each aob In CurrentProject.AllForms
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acForm, aob.Name, aob.Name
-
Next
-
-
'Export all Reports
-
For Each aob In CurrentProject.AllReports
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acReport, aob.Name, aob.Name
-
Next
-
-
'Export all Macros
-
For Each aob In CurrentProject.AllMacros
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acMacro, aob.Name, aob.Name
-
Next
-
-
'Export all Modules
-
For Each aob In CurrentProject.AllModules
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acModule, aob.Name, aob.Name
-
Next
-
-
DoCmd.Hourglass False
-
End Function
P.S. - Just realized that you are using Access 2007. In that case, change the File Extension in Code Lines 12 (Comment), 13, and 16 to .accdb.
9 11138
You may run into problems attempting to Backup the Current Database, so your best option may be to create a New Database with the Date appended to the Name, then export selectrive Objects to it.
Hi ADezzi, you are right, I already ran into problems, but I found few webpages where people have said they found the way... using APIs, modules, functions and macros... but was not published the steps and the final coding... I tried for many hours all the "intermediate" processes posted without lack. What makes me holding faith is "tools, database utilities, and backup database" do the magic, if the Access 2003 has those 3 clicks, should be some way to replicate the same.
Following your line of thoughts, do you have the code behind the button to export/import all the objects from a database?
Take care
The code would be considerable, but when I get a chance I'll post a Template that you can work from.
OK, Thanks. I'll wait for it
The following code will Backup all Database Objects to a Folder specified by the Constant conPATH_TO_BKUPS (Line #3). You can change this if you wish, but be sure to add the Trailing Backslash since I did not test for this for the sake of brevity. The actual Back Up Database will be the Base Name of the Current Database minus the .mdb Extension, plus an Underscore (_), plus the Date formatted as mmddyyyy, plus .mdb. Each Backup will be unique only as far as a single Day is concerned and will DELETE a previous Backup for that Day should it exist. I intentionally placed the code in a Public Function where it can easily and directly be called from a Main Switchboard Item. Have fun, and if you have any questions, please feel free to ask. - Public Function fExportAllDBObjects()
-
On Error Resume Next
-
Const conPATH_TO_BKUPS As String = "C:\DB Backups\"
-
Dim strAbsoluteBkUpPath As String
-
Dim aob As AccessObject
-
Dim strDBName As String
-
Dim wrkSpace As Workspace
-
Dim dbBackup As Database
-
-
DoCmd.Hourglass True
-
-
'Retrive the Current Database Name only, strip out .mdb
-
strDBName = Replace(Mid$(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1), ".mdb", "")
-
-
'Make the Backup DB Name unique for each Date
-
strDBName = strDBName & "_" & Format$(Date, "mmddyyyy") & ".mdb"
-
-
strAbsoluteBkUpPath = conPATH_TO_BKUPS & strDBName
-
-
'If a Bacup already exists for this Date, then DELETTE it
-
If Dir$(strAbsoluteBkUpPath) <> "" Then
-
Kill strAbsoluteBkUpPath
-
End If
-
-
'Get Default Workspace.
-
Set wrkSpace = DBEngine.Workspaces(0)
-
-
'Create the Database
-
Set dbBackup = wrkSpace.CreateDatabase(strAbsoluteBkUpPath, dbLangGeneral)
-
-
'Export all Tables
-
For Each aob In CurrentData.AllTables
-
If Mid$(aob.Name, 2, 3) <> "Sys" Then 'Don't Export System Tables
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acTable, aob.Name, aob.Name
-
End If
-
Next
-
-
'Export all Queries
-
For Each aob In CurrentData.AllQueries
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acQuery, aob.Name, aob.Name
-
Next
-
-
'Export all Forms
-
For Each aob In CurrentProject.AllForms
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acForm, aob.Name, aob.Name
-
Next
-
-
'Export all Reports
-
For Each aob In CurrentProject.AllReports
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acReport, aob.Name, aob.Name
-
Next
-
-
'Export all Macros
-
For Each aob In CurrentProject.AllMacros
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acMacro, aob.Name, aob.Name
-
Next
-
-
'Export all Modules
-
For Each aob In CurrentProject.AllModules
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acModule, aob.Name, aob.Name
-
Next
-
-
DoCmd.Hourglass False
-
End Function
P.S. - Just realized that you are using Access 2007. In that case, change the File Extension in Code Lines 12 (Comment), 13, and 16 to .accdb.
Hi ADezzi,
Many Thanks!!!!
The code you posted works splendid!!!!
Thanks again!
Juan
You are quite welcome, Juan.
This backup works very well. I adapted it to remove the date feature. How would one restore the same file it created from ie an external drive and replace the existing file?
I changed the code as shown below to export data to my e:drive - On Error Resume Next
-
Const conPATH_TO_BKUPS As String = "e:\"
-
Dim strAbsoluteBkUpPath As String
-
Dim aob As AccessObject
-
Dim strDBName As String
-
Dim wrkSpace As Workspace
-
Dim dbBackup As Database
-
-
DoCmd.Hourglass True
-
-
'Retrive the Current Database Name only, strip out .mdb
-
strDBName = Replace(Mid$(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1), ".accdb", "")
-
-
'Make the Backup DB Name unique for each Date
-
strDBName = strDBName & ".accdb"
-
'& "_" & Format$(Date, "mmddyyyy")
-
strAbsoluteBkUpPath = conPATH_TO_BKUPS & strDBName
-
-
'If a Bacup already exists for this Date, then DELETTE it
-
If Dir$(strAbsoluteBkUpPath) <> "" Then
-
Kill strAbsoluteBkUpPath
-
End If
-
-
'Get Default Workspace.
-
Set wrkSpace = DBEngine.Workspaces(0)
-
-
'Create the Database
-
Set dbBackup = wrkSpace.CreateDatabase(strAbsoluteBkUpPath, dbLangGeneral)
-
-
'Export all Tables
-
For Each aob In CurrentData.AllTables
-
If Mid$(aob.Name, 2, 3) <> "Sys" Then 'Don't Export System Tables
-
DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
-
acTable, aob.Name, aob.Name
-
End If
-
Next
-
-
-
-
DoCmd.Hourglass False
- Make a Backup Copy of your Data and other Objects.
- DELETE Slective Objects from the Current Database.
- Import Selective Objects from the External Database to replace those Deleted from the Current Database.
- Should any part of this process fail, aside from the Backup, you will still have the Backup to return to.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Neil |
last post by:
Hi,
I hope this question isn't too far off topic....I'm almost at my wits
end trying to figure this out.
I have a Mysql database and I wish to automate the backup of the
database because I...
|
by: TThai |
last post by:
Hi,
Appreciated anyone who can help us with our problem. Our backup job
for ROUTT database has been failing for the last 4 days. It was
working fine for almost a year now. The only thing...
|
by: Charles Morrall |
last post by:
I have no experience with DB2 as such, but I've been tasked with configuring
backup of a server running DB2 v8 on Windows Server 2003. I do have some
experience with backups in general though. The...
|
by: Skully Matjas |
last post by:
Is there a wat to make a command button for a backup of the database to
floppy discs.
1) I would rather just back up the information I have in the Tables.
Because that way it could fit onto...
|
by: Richard Hollenbeck |
last post by:
I'd like a button on my main form to backup the database. How can I call up
the Windows folder browser to prompt me for a filename and type (*.mdb) and
folder to save in? I looked in my book and...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: alanchinese |
last post by:
i am a db2 newbie. we have a server hosting a db2/6000 database that
restricts the use of backup, generate ddl. i wonder if there is a
simple way to transfer the database structure and data into my...
|
by: Dököll |
last post by:
Jumped for joy last night after learning, indeed, the command button wizard can be switched on or off. Well this occured here, with my Access 2000...an attempt to redo at work failed.
Here's the...
|
by: ARC |
last post by:
Does anyone know if you can add your own items to the round office button in
the top left? I'm guessing the answer is no, and that you can only hide the
default items, but it would be great if you...
|
by: Tony |
last post by:
I am continuing to develop an Access 2007 application which was
originally converted from Access 2003. In Access 2003 I was able to
disable the Access Close button in the top righthand corner of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |