Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup and Restore Access Database from Access using VB

Status
Not open for further replies.

kevinforbes

Programmer
Apr 3, 2002
27
0
0
CA
Hi there,

Forgive me if this question has already been answered but I cannot search since it is down for maintenance at the moment. Please point me to the thread if applicable.

From MS Access, I need to run VB Code to create a backup database at C:\backup_db\current_filename_bak.mdb containing all of the tables from the current database by a click of a button on one of my forms.

I understand the methodology but have been bouncing between several different languages and am at a loss for the actual code and syntax.

Any help would be very much appreciated.
thanks,
K

 
Sorry, forget to mention I am using Access 2002 and VB 6

tx
 
hi,
i suppose u can use the filesystemobject to copy the file.
or prompt a filedialog to save teh mdb to new location with a different filename.

regards
john philip *** Even the Best, did the Bad and Made the Best ***

John Philip
Software Programmer
JustDial Services, Mumbai
johnphilip@justdial.com
 
You can also look at JRO (Jet and Replication Objects) in VBHelp
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
hi,

try this one:

Sub BackUp()

dim strDestination, strSource as string

strSource = "C:\Source_db\current_filename_orig.mdb"
'just update with the correct path of your source dbase

strDestination = "C:\backup_db\current_filename_bak.mdb"

FileCopy strSource, strDestination

End Sub

regards,
Rodel Ocfemia
 
Thanks, those will probably do the trick. However, I only want to backup the tables, how about this...

--------------------------------------------------
Private Sub backupDb()
Dim retval As Boolean
retVal = MsgBox("Backup data?")
'get current db filename
'check for file at c:backup_db\filename.mdb
if NOT fileExists
'create the file
else
'remove all data (or move it to _bak tables)
end if

'create connection to destination db
'loop through table collection
For Each tdfTable In currentDB.TableDefs
SELECT * INTO new_table FROM orig_table
Next

End Sub

---------------------------------------------
1. How do I get the current database object?
2. Do I need to make a connection to the source and destination (How would the query code look)?
3. How do I create the new destination file if it doesn't already exist?

tx
 
I don't know if this will interest you or not, but I am using the following: "Timeless Technologies AppBackup."

It is not free, but seems to work very well.

Good luck,
Bojangles
 
Thanks, unfortunately it is something that has to be done programmatically and free !

tx
 
kevinforbes

I would suggest that you follow johnwm's suggestion as using the JRO will allow you to compact (strip out all deleted rows and generally tidy the MDB file up) at the same time.

matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top