You can use several methods. Depending on your app one will be best for your situation. If you are using the Access Object Model then see my FAQ. If you are not using the Access Object Model then use JRO.
Code:
'Add a ref to MS Jet and Replication Objects X.X library...
Dim jro As jro.JetEngine
Set jro = New jro.JetEngine
jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nwind2.mdb;Jet OLEDB:Database Password=test", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\abbc2.mdb;Jet OLEDB:Engine Type=4;Jet OLEDB:Database Password=test"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
There is Rollback sub routine in there, try to explore a little bit.I had not specifically used it since the CompactDatabase routine was the one I used.
''' <param name="dataBaseName">Here the database Name is the Name of the Databse you are passing</param>
''' <remarks></remarks>
Sub FileRestore(ByVal dataBaseName As String)
Try
Me.OpenFileDialog.ShowDialog()
If String.Equals(IO.Path.GetFileName(Me.OpenFileDialog.FileName), dataBaseName) Then
If MessageBox.Show("Do you want to Restore the Database?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then Exit Sub
IO.File.Delete(IO.Path.Combine(Application.StartupPath, dataBaseName)) 'Deleting The Old File
IO.File.Copy(Me.OpenFileDialog.FileName, IO.Path.Combine(Application.StartupPath, dataBaseName)) ' Making A Copy Of That File