hi there,
do you have any sample code that will compact and repair mdb file 2002 thru vb6
thanks,
alexis
Printable View
hi there,
do you have any sample code that will compact and repair mdb file 2002 thru vb6
thanks,
alexis
check this out..
I have found this piece of code in the code repository of this forum..
vb Code:
Option Explicit Private Sub Command1_Click() On Error GoTo MyError Dim oApp As Access.Application Set oApp = New Access.Application oApp.DBEngine.CompactDatabase "D:\INVOICE.mdb", "D:\INVOICECpd.mdb" Kill "D:\INVOICE.mdb" Name "D:\INVOICECpd.mdb" As "D:\INVOICE.mdb" MsgBox "Compact Complete!", vbOKOnly oApp.Quit acQuitSaveNone Set oApp = Nothing Exit Sub MyError: MsgBox Err.Number & " - " & Err.Description, vbOKOnly End Sub
The only issue with the code posted above is that you need to have access installed on the system to compact / repair the mdb.Quote:
Originally Posted by alexis23
Take a look at this post.
Make sure you reference this in VB IDE.
Go To Project> Reference
Microsoft ActiveX Data Objects 2.x Library
Microsoft Jet and Replication Objects 2.x Library
You can also use the command line switche to run this out of sync.
Shell("PathToAccess\Access"" \Compact"" ""DatabaseFile"" ")
Hi all
I tried this code and come with compile error:
user define type not define
reference to thisCode:Option Explicit
Private Sub Command1_Click()
On Error GoTo MyError
Dim oApp As Access.Application
Set oApp = New Access.Application
oApp.DBEngine.CompactDatabase "D:\INVOICE.mdb", "D:\INVOICECpd.mdb"
Kill "D:\INVOICE.mdb"
Name "D:\INVOICECpd.mdb" As "D:\INVOICE.mdb"
MsgBox "Compact Complete!", vbOKOnly
oApp.Quit acQuitSaveNone
Set oApp = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
End Sub
Microsoft ActiveX Data Objects 2.x Library
Microsoft Jet and Replication Objects 2.x Library
I am using vb6 and access 2003
Thanks in advance
Regard,
Cesin
Quote:
Originally Posted by ksuwanto8ksd
You have to set the references to the lib files through your project->references view, as zynder explained earlier.Quote:
Originally Posted by zynder
NEATO is right.
you have to set the references first then try the code.
Moved to database development
when a DB is compacted is it also repaired??