I have a VB6 application that I use to compact any version of access using the function below. I use input boxes for the user to input the version, and the password (in any).
The only part I can't get working is the Security part for databases using Workgroup security. It does work for all the hundreds of other Access applications on our hospital server.
Based on the version entered I set the JetEngine type as shown in the first code snippet.
If RS!DBType = "97" Then
lnVersion = 4
ElseIf RS!DBType = "2000" Or RS!DBType = "2002" Or RS!DBType = "2003" Then
lnVersion = 5
End If
....various other code to pass parameters to function...
Public Function Compact(sSource As String, sDestination As String, Optional sSecurity As String, Optional sUser As String, Optional sPassword As String, Optional lVersion As Long) As Boolean
Dim sCompactPart1 As String
Dim sCompactPart2 As String
Dim oJet As JRO.JetEngine
'build string for source database
sCompactPart1 = "Provider=Microsoft.Jet.OLEDB.4.0" & ";Data Source=" & sSource & ";User Id=" & sUser & ";;Jet OLEDB

atabase Password='" & sPassword & "'"
'THIS IS WHERE I WOULD LOVE SOME HELP!
If sSecurity <> "" Then
'TRIED ALL THREE BELOW AND NONE WORK
sCompactPart1 = sCompactPart1 & ";Jet.OLEDB:System database=" & sSecurity & ";"
'sCompactPart1 = sCompactPart1 & ";Jet.OLEDB:System database=" & sSecurity
'sCompactPart1 = sCompactPart1 & ";Jet OLEDB:System database=" & sSecurity & " "
End If
'build string for destination database
sCompactPart2 = "Provider=Microsoft.Jet.OLEDB.4.0" & ";Data Source=" & sDestination
If sPassword <> "None" Then
sCompactPart2 = sCompactPart2 & ";User Id=" & sUser & ";;Jet OLEDB

atabase Password='" & sPassword & "'"
End If
If lVersion <> 0 Then
sCompactPart2 = sCompactPart2 & ";Jet OLEDB:Engine Type=" & lVersion
End If
'compact and give original name to compacted database
Set oJet = New JRO.JetEngine
oJet.CompactDatabase sCompactPart1, sCompactPart2
Set oJet = Nothing
Compact = True
End Function
Hope this is helpful and I hope someone can return code to compact databases protected by workgroup security.