Does anyone know how to run Access compact and repair database from VB6 code? Also can you run an Access report using VB code? Thanks for your help.
Printable View
Does anyone know how to run Access compact and repair database from VB6 code? Also can you run an Access report using VB code? Thanks for your help.
For Repair you can use:
DBEngine.RepairDatabase "C:\MyDB.mdb"
For Compacting:
Regards,Code:Dim strTempDB As String
Dim strDBName As String
strDBName = "C:\MyDB.mdb"
strTempDB = "C:\Temp.mdb"
DBEngine.CompactDatabase strDBName, strTempDB
Name strTempD As strDBName
------------------
Serge
Software Developer
[email protected]
[email protected]
Hello Serge. I tried using this codes but I think i am missing a project reference or component. Could you please tell me what reference or component I should include with my project? Thanks a bunch.
VB Code:
Dim strTempDB As String Dim strDBName As String strDBName = "C:\MyDB.mdb" strTempDB = "C:\Temp.mdb" DBEngine.CompactDatabase strDBName, strTempDB ' What is This? Name strTempD As strDBName
Any on know what is DbEngine? :confused:
You need to set a reference to Microsoft DAO Library.
Its Works, Thaks :DQuote:
Originally posted by pnish
You need to set a reference to Microsoft DAO Library.
But Can I Do It With ADO? :rolleyes:
I'm not sure how to do it with ADO. Have a look at this post and see if it helps:
http://www.vbforums.com/showthread.p...hreadid=201558
VB Code:
Public Function CompactDatabase(strFileName As String) As Long ' Add the references ' Microsoft Jet and Replication Objects 2.x Library Screen.MousePointer = vbHourglass Dim msg As String Dim strFileNameBackup As String Dim JRO As JRO.JetEngine strFileNameBackup = Left(strFileName, Len(strFileName) - 3) & "~db" On Local Error Resume Next Kill strFileNameBackup On Error GoTo ErrorLine Name strFileName As strFileNameBackup Set JRO = New JRO.JetEngine JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileNameBackup, _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName & ";Jet OLEDB:Engine Type=5" Kill strFileNameBackup Screen.MousePointer = vbDefault Exit Function ErrorLine: CompactDatabase = Err.Number End Function