Repair and Backup MDB

A

Ari

Hello Group!

How I do so that an application makes the following thing:

1- On Close the application repairs and compacts (Both things)
2- On Close the application do a Backup of the same one in a specific route.

Thanks!
 
D

Douglas J Steele

Access 2000 and later have an option available to compact on close (sorry, I
only have Access 97, so I can't point you to the exact location)

Assuming your database is split into a front-end (containing the queries,
forms, reports, macros and modules), linked to a back-end (containing the
tables), all you really need to backup is the back-end. What I typically do
is use a function like:

Sub CompactDatabase( _
DatabaseName As String _
)
' Renames the existing database to a new file name
' (with the date in it), then compacts that file to
' the "proper" database name.

Dim strTempFile As String

If Len(Dir$(DatabaseName)) > 0 Then

strTempFile = Left$(DatabaseName, _
Len(DatabaseName) - 4) & _
Format(Date(), "yyyymmddhhnn") & ".mdb"
If Len(Dir$(strTempFile)) > 0 Then
Kill strTempFile
End If

Name DatabaseName As strTempFile

DBEngine.CompactDatabase strTempFile, DatabaseName

End If

End Function
 
A

Ari

Hi, thanks for aswer.

No, I have all in a MDB file!!!

Tanks!!

--------------------------------------------------------------------------------
 
D

Douglas J Steele

Hopefully you don't have multiple users: sharing a monolithic database is a
sure recipe for corruption! Even my single user stand-alone databases are
always split, but I guess that's your perogative.

You should never copy a database that's open. While there are some
techniques that will let you do so, you run the risk of leaving the database
in an inconsistent stated.

Take a look at MichKa's TSI SOON (Shut One, Open New) database add-in at
http://www.trigeminal.com/utility.asp?ItemID=8#8 Your "new" database can
copy the "old" one.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hi, thanks for aswer.

No, I have all in a MDB file!!!

Tanks!!
 
Top