Last active
August 19, 2019 22:48
-
-
Save facebookegypt/e5c58d1cbe97bb905a54 to your computer and use it in GitHub Desktop.
VB 2010 MS-Access 2003 Database compact and repair programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Example vb.net Using COM JRO.JetEngine Liberary | |
'That works fine with Microsoft access 2000-2003 MDB file | |
Module Module1 | |
Sub Main() | |
Dim jro As JRO.JetEngine | |
jro = New JRO.JetEngine() | |
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\nwind.mdb", _ | |
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NewNwind.mdb;Jet OLEDB:Engine Type=5") | |
MsgBox("Finished Compacting Database!") | |
End Sub | |
End Module | |
'======================================= | |
'Example vb.net Using .Net DAO.DBEngine Liberary | |
'That works fine with Microsoft access 2007-2010 accdb file | |
'Open your OLEDBConnection | |
'Compact & Repair needs the Database File (*.accdb) to be closed. | |
Dim MyAccDB As New Microsoft.Office.Interop.Access.Dao.DBEngine() | |
Dim Compactedfil As String = "PATH_TO_New_Compacted_ACCDB_FILE" | |
MyAccDB.CompactDatabase("Current_connected_accdb_location", Compactedfil, , , ";pwd=database_password") | |
My.Computer.FileSystem.DeleteFile(DBLocation) 'Delete Current_connected_accdb_location | |
Rename(Compactedfil, DBLocation) | |
Application.DoEvents() 'Wait | |
'Any code here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment