Results 1 to 10 of 10

Thread: [RESOLVED] [2005] Compact And Repair

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] [2005] Compact And Repair

    Hi all
    How to compact and repair the access database at run time.
    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Compact And Repair

    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.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    Re: [2005] Compact And Repair

    Take a look a these and give it a try.I will try to attach the dll file so that you can use this code.

    vb Code:
    1. Private Sub CompactAccessDatabase()
    2.         Try
    3.  
    4.             Dim File_Path, compact_file As String
    5.             'Original file path we are about to compact
    6.             File_Path = "C:\Your File Name.mdb"
    7.             'compact file path, a temp file
    8.             compact_file = "C:\Any Name You Want.mdb"
    9.             If File.Exists(File_Path) Then
    10.                 Dim db As New DAO.DBEngine
    11.                 db.CompactDatabase(File_Path, compact_file)
    12.             End If
    13.             'Restore the original file from the compacted file
    14.             If File.Exists(compact_file) Then
    15.                 File.Delete(File_Path)
    16.                 File.Move(compact_file, File_Path)
    17.             End If
    18.             MessageBox.Show("Compacting database successfully completed", "Compact", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
    19.  
    20.         Catch ex As Exception
    21.             MessageBox.Show(ex.Message, "Compact and Repair Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    22.         End Try
    23.     End Sub

  4. #4
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    Re: [2005] Compact And Repair

    Here's the attach dll file, make it as your reference.
    Attached Files Attached Files
    Last edited by aldrean; Apr 23rd, 2007 at 02:21 AM.

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Compact And Repair

    @aldrean
    Send ame the zip file I donot have rar install
    Thanks

  6. #6
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    Re: [2005] Compact And Repair

    I had change it as you requested.Hope it helps.

  7. #7

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Compact And Repair

    @aldrean
    Have you any idea about the restore the databse

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Compact And Repair

    Why use all that extra complication? See post #2. Simple and sweet.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    Re: [2005] Compact And Repair

    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.

  10. #10

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Compact And Repair

    This Code Restore the Database

    vb Code:
    1. ''' <summary>
    2.     ''' This sub is used for the database restore
    3.     ''' 1) Add the Open File Dialog Control
    4.     ''' 2) Imports System.IO
    5.     ''' </summary>
    6.     ''' <param name="dataBaseName">Here the database Name is the Name of the Databse you are passing</param>
    7.     ''' <remarks></remarks>
    8.     Sub FileRestore(ByVal dataBaseName As String)
    9.         Try
    10.             Me.OpenFileDialog.ShowDialog()
    11.             If String.Equals(IO.Path.GetFileName(Me.OpenFileDialog.FileName), dataBaseName) Then
    12.                 If MessageBox.Show("Do you want to Restore the Database?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then Exit Sub
    13.  
    14.                 IO.File.Delete(IO.Path.Combine(Application.StartupPath,  dataBaseName)) 'Deleting The Old File
    15.                 IO.File.Copy(Me.OpenFileDialog.FileName, IO.Path.Combine(Application.StartupPath, dataBaseName)) ' Making  A Copy Of That File
    16.                 MessageBox.Show("Database Successfully Restored", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    17.             Else
    18.                 MessageBox.Show("Incorrect File Name", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    19.             End If
    20.         Catch ex As Exception
    21.             MessageBox.Show(ex.Message, "Contact IFW Creations", MessageBoxButtons.OK, MessageBoxIcon.Error)
    22.         End Try
    23.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width