|
-
Sep 19th, 2007, 03:01 AM
#1
Thread Starter
Fanatic Member
Backup Database within access
I'm trying to develope a backup functionality to a database for a small job.
There's a few other things too, but they have been resolved.
What i'm looking to produce is somthing that backs up the database like the File>Back Up Database does.
The only thing i wish to change is the filename in the filename textbox. The person requests this as a button on the form.
So when the user clicks the button on a form the backup database form should show up, but with the file name changed to some data.
Calling the winow is fine, however figuring out how to change the file name... a hassle.
Code:
CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Back Up Database..."). _
accDoDefaultAction
I wasn't sure if this should go in the database threads, but decided this was the best place.
Last edited by Slyke; Sep 19th, 2007 at 03:16 AM.
-
Sep 19th, 2007, 05:46 AM
#2
Re: Backup Database within access
Are you trying to do with from within Access itself?
-
Sep 19th, 2007, 08:45 AM
#3
Thread Starter
Fanatic Member
Re: Backup Database within access
Yes, with a command button on a form (Using the VBA editor).
-
Sep 19th, 2007, 09:04 AM
#4
Re: Backup Database within access
I think Access needs to be closed before you can make a copy of it, so I would write a backup program that runs external to Access.
-
Sep 19th, 2007, 09:42 AM
#5
Thread Starter
Fanatic Member
Re: Backup Database within access
Yes, the "Back Up Database" menu does that, it closes the database, displays a dialog box asking where to make the backup to, with a filename, then reopens the database after the process has been completed. All in access.
The menu is File>Back Up Database.
The code i posted in the first post displays this dialog box when the user clicks the command button. What i'm asking is how to change the default filename in the dialog box before it opens up.
The reason that the person wanted this is because it's tedious changing numbers (dates) in the filename since the default filename is today's date, when actually, we want the database date (in the filename) to be another time.
The data that will be placed in the backup's filename is from some data in the database.
So unless the database can have some code that closes itself, execute some code to copy the closed database, and then reopen itself externally back to it's original state, this is really the only way to do it. Also using this method, most of that is already done (except the file name!!!).
See the attached images:
Backup Dialog:

Where to find it in the menu system:
Last edited by Slyke; Sep 19th, 2007 at 09:58 AM.
-
Sep 19th, 2007, 12:19 PM
#6
Re: Backup Database within access
 Originally Posted by Slyke
So unless the database can have some code that closes itself, execute some code to copy the closed database, and then reopen itself externally back to it's original state, this is really the only way to do it. Also using this method, most of that is already done (except the file name!!!).
This is actually easier than you might think. Have the Access backup function call an exe then close itself. (The current database.) If that's tricky, just have it quit access instead.
The VB6 exe should open a "Save As" common dialogue. It's easy to specify a default filename of your choosing. If the user presses the Cancel button on the Save As dialog, skip this next paragraph.
After the user picks a file, the exe (using a timer) checks for the existance of the ldb file, waiting for it to disappear. (This means that nobody is using the database.) Now that you have exclusive access, make a copy of the Access database by compacting it to the new name.
Now use ShellExecute API to run the original Access database.
All four aspects of this (the common dialog, waiting for the locking file to go away, compacting the database, and ShellExecuting an Access database) are very easy, and I'd be happy to help you with any or all of them if you like.
(Note that the link above for compacting a database doesn't let you specify a destination name, and in fact overwrites the original database with the compacted version. This would obviously need to be altered.)
-
Sep 19th, 2007, 01:15 PM
#7
Re: Backup Database within access
 Originally Posted by Ellis Dee
The VB6 exe should open a "Save As" common dialogue. It's easy to specify a default filename of your choosing. If the user presses the Cancel button on the Save As dialog, skip this next paragraph.
After the user picks a file, the exe (using a timer) checks for the existance of the ldb file, waiting for it to disappear. (This means that nobody is using the database.) Now that you have exclusive access, make a copy of the Access database by compacting it to the new name.
Now use ShellExecute API to run the original Access database.
This is exactly what I was thinking of when I did Post #4
-
Sep 19th, 2007, 07:50 PM
#8
Thread Starter
Fanatic Member
Re: Backup Database within access
Kk, i will make a small external exe that will be executed from inside the database, pass the default filename (The default filename that i changed) using a parameter and use a save as dialog box. Once this is done, compact (i'll prolly need help with this one) the database and then re-execute it.
How can i get the database's filename before it shuts (so that the exe knows what to copy)? Like inside the VBA editor what's the command to get the filename of the DB?
-
Sep 20th, 2007, 08:57 AM
#9
Re: Backup Database within access
 Originally Posted by Slyke
...inside the VBA editor what's the command to get the filename of the DB?
CurrentDb.Name holds the full path & filename of the current database.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|