PC Review


Reply
Thread Tools Rate Thread

access 2007 compact creates new database

 
 
Michel Peeters
Guest
Posts: n/a
 
      4th Nov 2007
I am using following code to compact my database.
this worked ok in Access 2000 but in 2007 after compacting I find a new
(compacted) database; the original database did not change.
I want my original database to compact and I do not need a new one.
How can I fix this?


Declare Function TSB_API_GetExitCodeProcess Lib "kernel32" Alias
"GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function TSB_API_OpenProcess Lib "kernel32" Alias "OpenProcess"
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessId As Long) As Long

Sub CompactMijnDB(theDBName As String)

Dim myString As String
Dim IsComplete As Double
Dim strDC As String
strDC = """"
Debug.Print strDC
Debug.Print myString
myString = "C:\Program Files\Microsoft Office\Office12\MSAccess.exe " &
strDC & theDBName & strDC & " /compact" & strDC
Debug.Print myString
If SysInfoWaitForApp_TSB(myString, vbNormalFocus) = True Then
'MsgBox "target compacted"
Else
Stop 'do whatever you want here..
End If
Exit Sub

End Sub

Function SysInfoWaitForApp_TSB(strCommandLine As String, intMode As Integer)
As Boolean
' Comments : runs the specified app and waits for its termination
' Parameters: strCommandLine - command line for program to execute
' intMode - mode for Shell command (search Access Help for
"Shell")
' Returns : True if successful, False otherwise
'
Dim hInstance As Long
Dim hProcess As Long
Dim lngRet As Long
Dim lngExit As Long

Const ProcessQueryInformation = &H400
Const StillActive = &H103

On Error GoTo PROC_ERR

' Launch the application
hInstance = Shell(strCommandLine, intMode)

' Get a process handle
hProcess = TSB_API_OpenProcess(ProcessQueryInformation, True, hInstance)

' Wait until the process ends
Do
lngRet = TSB_API_GetExitCodeProcess(hProcess, lngExit)

' Yield to the operating system
DoEvents
Loop Until lngExit <> StillActive

SysInfoWaitForApp_TSB = True

PROC_EXIT:
Exit Function

PROC_ERR:
SysInfoWaitForApp_TSB = False
Resume PROC_EXIT

End Function



tks
Michel


 
Reply With Quote
 
 
 
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      4th Nov 2007
The process of compaction always creates a new database, writes the data and
objects to it, leaving behind any corrupted or deleted data or objects. Once
created, it deletes the current database and renames the new one. This has
been the process since the first compaction capability.

What you are seeing is a failure to delete and rename the database. That
could be because of delete permissions on the file or folder not being
allowed, or some other failure caused by your file system. If you are also
operating on Microsoft Vista, that is the most probable cause.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Michel Peeters" <(E-Mail Removed)> wrote in message
news:7qkXi.9140$(E-Mail Removed)...
>I am using following code to compact my database.
> this worked ok in Access 2000 but in 2007 after compacting I find a new
> (compacted) database; the original database did not change.
> I want my original database to compact and I do not need a new one.
> How can I fix this?
>
>
> Declare Function TSB_API_GetExitCodeProcess Lib "kernel32" Alias
> "GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As Long
> Declare Function TSB_API_OpenProcess Lib "kernel32" Alias "OpenProcess"
> (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
> dwProcessId As Long) As Long
>
> Sub CompactMijnDB(theDBName As String)
>
> Dim myString As String
> Dim IsComplete As Double
> Dim strDC As String
> strDC = """"
> Debug.Print strDC
> Debug.Print myString
> myString = "C:\Program Files\Microsoft Office\Office12\MSAccess.exe " &
> strDC & theDBName & strDC & " /compact" & strDC
> Debug.Print myString
> If SysInfoWaitForApp_TSB(myString, vbNormalFocus) = True Then
> 'MsgBox "target compacted"
> Else
> Stop 'do whatever you want here..
> End If
> Exit Sub
>
> End Sub
>
> Function SysInfoWaitForApp_TSB(strCommandLine As String, intMode As
> Integer) As Boolean
> ' Comments : runs the specified app and waits for its termination
> ' Parameters: strCommandLine - command line for program to execute
> ' intMode - mode for Shell command (search Access Help for
> "Shell")
> ' Returns : True if successful, False otherwise
> '
> Dim hInstance As Long
> Dim hProcess As Long
> Dim lngRet As Long
> Dim lngExit As Long
>
> Const ProcessQueryInformation = &H400
> Const StillActive = &H103
>
> On Error GoTo PROC_ERR
>
> ' Launch the application
> hInstance = Shell(strCommandLine, intMode)
>
> ' Get a process handle
> hProcess = TSB_API_OpenProcess(ProcessQueryInformation, True, hInstance)
>
> ' Wait until the process ends
> Do
> lngRet = TSB_API_GetExitCodeProcess(hProcess, lngExit)
>
> ' Yield to the operating system
> DoEvents
> Loop Until lngExit <> StillActive
>
> SysInfoWaitForApp_TSB = True
>
> PROC_EXIT:
> Exit Function
>
> PROC_ERR:
> SysInfoWaitForApp_TSB = False
> Resume PROC_EXIT
>
> End Function
>
>
>
> tks
> Michel
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compact database in VBA access 2007 SL Microsoft Access VBA Modules 5 2nd Feb 2010 08:31 PM
Access 2007 compact database Tony WONG Microsoft Access 1 21st Mar 2008 08:27 AM
Access 2007 - compact database Tony WONG Microsoft Access 2 20th Aug 2007 12:01 PM
How do I compact an Access database in 2007? =?Utf-8?B?Q3Jpcw==?= Microsoft Access 3 21st Mar 2007 05:44 AM
how can I compact an Access 2007 database =?Utf-8?B?amFua3Jv?= Microsoft Access 1 9th Feb 2007 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:48 PM.