Yeah, look up the Jet Replication Object (JRO Library) They should have good info in the MSDN on repairing and compacting a DB from VB, regardless of which version of DAO you use.
I believe it is listed under the References dialogue as Microsoft Jet and Replication objects 2.5 library, and the filename is msjro.dll. It should be there on your system somewhere, if it is not I can email the .dll to you if you would like.
Just did it and the database when opened needs to be repaired. I have tried 2 different ways to compact it
1) Dim jro As jro.JetEngine
Set jro = New jro.JetEngine
jro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\nwind2.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\abbc2.mdb;Jet OLEDB:Engine Type=4"
Both leave me with a mdb that needs to be repaired
VB gets a runtime error that says it needs to be repaired and when I open it in Access it tells me the same.
Try downloading the latest service packs, and try it again. Also, maybe someone opened an Access 97 db in Access 2000, converted it, and now you are trying to open it in 97? That's a thought. Or the database (Johnathon123) might be screwed up beyond all recognition. If the database is on a shared network drive, I would copy it to my local machine and try the repair again.
These are reasons 1, 2, and 3 I upgraded to SQL Server.
When it is fixed, it is fine. The only issue is when I compact it again it messes it up.
The compact feature in code is what is messing it up.
I am currently the only user as it is still in development stages so that rules out many possiblities.
Update to MDAC 2.6 and Jet 4.0. The following does work...
Private Sub mnuRepairDatabase_Click()
Dim fso As New FileSystemObject, File1 As File
Dim je As New JRO.JetEngine
'Set objDB = Nothing 'only used if the database is opened from a class module
' Make sure that a file doesn't exist with the name of
' the compacted database.
If Dir(App.Path & "\Sys\MyDB2.mdb" <> "" Then
Kill App.Path & "\Sys\MyDB2.mdb"
End If
If Dir(App.Path & "\Sys\MyDB2.mdb" <> "" Then
Kill App.Path & "\Sys\MyDB.mdb"
Set File1 = fso.GetFile(App.Path & "\Sys\MyDB2.mdb"
File1.Copy App.Path & "\Sys\MyDB.mdb"
End If
MsgBox "Database Repair Complete"
Exit Sub
errorhandler:
If Err = -2147467259 Then
'Err.Description
MsgBox "Error# " & Err & " -> " & Err.Description
End If
End Sub
If the database is open by another user, the error will occur
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.