Run Backup Code in VBA

gschimek

Registered User.
Local time
Today, 14:43
Joined
Oct 2, 2006
Messages
102
I'm having trouble with some code to backup my database. I thought I'd just have some code call a batch file that copies the backend to a new location. The problem is that when I call the batch file, it opens and runs from c:\documents and settings\%username%\, so the relative paths in my batch file do not work.

Is there a way to have access tell run the batch file from command prompt in it's actual location? Or maybe it would be better just to copy the back end from within the VBA code. But I don't know how to do that, either. Maybe there's a way to use the Backup Database function under Tools/Database Utilities? With Sendkeys maybe? (but I don't know the code to do it).
 
A different approach...

This is how I do it. It will back up any file to a memorized location. I simply include it as part of my databases.

Dave
 

Attachments

That's a very nice solution, but it seems like it's a little more complicated than I'm really looking for. I'm hoping to find a simple way to just copy the backend from one location to another. But I can't use static path names because the database will not always be in the same directory name on every computer.

I do always want the backend copied from whatever folder it's in, to a subfolder called Backup. Any ideas?
 
gschimek said:
That's a very nice solution, but it seems like it's a little more complicated than I'm really looking for. I'm hoping to find a simple way to just copy the backend from one location to another. But I can't use static path names because the database will not always be in the same directory name on every computer.

I do always want the backend copied from whatever folder it's in, to a subfolder called Backup. Any ideas?

Use the connection sting of one of the liked tables that link to the data file but the data file should have the same location regardless of the computer ??

Code:
Dim M_Db As DAO.Database
Dim Tdf As TableDef
Dim Con As String

Set M_Db = CurrentDb()

Set Tdf = M_Db.TableDefs("Name of your table you want to use for this")
Con = Tdf.Connect
 
So I assume I can choose any table I want in place of "Name of your table you want to use for this", right?

And then when I put that code in, would I do somthing like:

copy Con ..\Backup

If I'm thinking correctly on that, then what's the VBA equivalent of that copy line?
 
Rate we're going I might as well write the whole thing for ya but the help files are a good place to start one way is the filesystemobject another is seach this forum as it's been covered god know's how many times IE Dir()

mick
 
Thanks for the direction (even with the rude tone of the response). Once you pointed out the terms Dir() and filesystemobject, I was able to search and came up with this simple line of code.

Code:
FileCopy CurrentProject.path & "\Tracking_be.mdb", CurrentProject.path & "\Backup\Tracking_be_backup.mdb"

And for the record, I do search, and always first. But most of the time I don't even know the right search term (e.g. filesystemobject). Hence, the posted question.

Again, thanks, and as mr_e_landis said "FileCopy source, destination. Who'd have thought?"
 
gschimek said:
Thanks for the direction (even with the rude tone of the response). Once you pointed out the terms Dir() and filesystemobject, I was able to search and came up with this simple line of code.

Code:
FileCopy CurrentProject.path & "\Tracking_be.mdb", CurrentProject.path & "\Backup\Tracking_be_backup.mdb"

And for the record, I do search, and always first. But most of the time I don't even know the right search term (e.g. filesystemobject). Hence, the posted question.

Again, thanks, and as mr_e_landis said "FileCopy source, destination. Who'd have thought?"

The easiest way to use the search in the vb Code window is think what do I want to do In This Case you wanted to copie a file so I would have started with a ms help and typed in "Copy File" I just did it and got about 40 results.

Didn't mean to be funny at all just saw something somebody else had posted to another help topic that wound me up.
 
Last edited:
Packup The Table only

A different approach...

This is how I do it. It will back up any file to a memorized location. I simply include it as part of my databases.

Dave

hi Oldsoftboss;
thanks for your db
I want backup from Tables only, beacuse my main data is in a table.
I used a code in below on click a button of form and then backup a table call "test" in my the db without unload the db.
Can I want help me to create select the path seem form "frmFlieName"?

Code:
Private Sub Command3_Click()
Dim makedb As Database
Dim namedir As String
Dim namefile As String
Dim strSQL As String
namefile = InputBox("Please Enter your Table for backup")
namedir = InputBox("Please Enter the path to backup into your db")
namedir = namedir & ".mdb"
Set ap = Application.FileSearch
ap.lookin = namedir
ap.filename = namefile
If ap.Execute = 0 Then
'strsql="SELECT nameshahr.CARD_NO INTO nameshahr IN 'D:\access\db1.mdb' from nameshahr;"
strSQL = "SELECT " & namefile & ".* INTO test IN '" & namedir & "' from " & namefile & ";"
DoCmd.RunSQL strSQL
Else
Exit Sub
End If
End Sub
thank:)
 

Users who are viewing this thread

Back
Top Bottom