jadams0173
Technical User
- Feb 18, 2005
- 1,210
I have a couple issues with the following code.
1. After the compact the password is not what I have specified in the connstringDest string.
2. If I step thru the code, I still have the password issue but the file size is correct. If I let it run at "speed" I end up with a DB with 0 KB in it that I still can't open.
Can anyone help please?
1. After the compact the password is not what I have specified in the connstringDest string.
2. If I step thru the code, I still have the password issue but the file size is correct. If I let it run at "speed" I end up with a DB with 0 KB in it that I still can't open.
Can anyone help please?
Code:
Public Function CompactDB(pFile As String) As Boolean
On Error GoTo ErrH
Dim conn As New JRO.JetEngine
Dim ConnstringSorg As String, ConnstringDest As String
' Ensure file is not read only
SetAttr pFile, vbNormal
ConnstringSorg = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & pFile & ";" & _
"Jet OLEDB:Database Password=word;"
ConnstringDest = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"G:\mypath\Temp.mdb; Jet OLEDB:Database Password=word:Engine Type=5;"
Screen.MousePointer = vbHourglass
conn.CompactDatabase ConnstringSorg, ConnstringDest
'compact and kill the file
Kill pFile
FileCopy "G:\mypath\Temp.mdb", pFile
Kill "G:\mypath\Temp.mdb"
Screen.MousePointer = vbDefault
Set conn = Nothing
CompactDB = True
Exit Function
ErrH:
Screen.MousePointer = vbDefault
Debug.Print Err.Description
End Function