Hi all. I have an access database that is updated with vba that runs in excel every day. It's sizeable. I need to compact it after every daily data "run." I run the two procedures back to back from excel. The first runs access macros. It might not have any real impact on what I'm trying to do, but I think it might since it uses an instance of the same database, just before the compact and repair procedure. All of this runs just fine without error, but the database doesn't compact. I have to do it manually every morning. Any suggestions? Here's the two macros that act on the access file from excel:
Code:
Sub AccessMacros()
'Execute the different append queries on the database to add the latest data to the
'points of interest table. Works by calling the access macro. We do it this way, instead
'of with excel code, since the excel/ access vba doesn't recognize udfs.
Dim strPath As String
Dim appAccess As Access.Application
strPath = "C:\Documents and Settings\User\Desktop\Business\Investments\TradeSystem\TradeSystem.accdb"
Set appAccess = New Access.Application
'Set appAccess = GetObject(strPath)
With appAccess
Application.DisplayAlerts = False
.OpenCurrentDatabase strPath
.DoCmd.RunMacro "macDeleteNewSymbolsTableRecords"
.DoCmd.RunMacro "macDeleteDups"
.DoCmd.RunMacro "macAppendToArchivesThenDeleteOldPricingVolData"
.DoCmd.RunMacro "macInactiveSymbsArchiveAndDeleteData"
.DoCmd.RunMacro "macDailyFunctionsUpdateTable"
Application.DisplayAlerts = True
.Quit
End With
Set appAccess = Nothing
End Sub
Sub CloseAndCompactDatabase()
'Opens and closes the access database to compact it.
Dim strPath As String
Dim appAccess As Access.Application
'Make sure alerts are turned off. We need this since without, there is a timeout error.
If Application.DisplayAlerts = True Then
Application.DisplayAlerts = False
End If
'Write the string for the file path.
strPath = "C:\Documents and Settings\User\Desktop\Business\Investments\TradeSystem\TradeSystem.accdb"
'Set the application object to the database. It seems to compact it upon opening.
Set appAccess = GetObject(strPath)
'Close the database.
With appAccess
.CloseCurrentDatabase
End With
'Turn alerts back on.
If Application.DisplayAlerts = False Then
Application.DisplayAlerts = True
End If
'Destroy the application object.
'Set appAccess = Nothing
End Sub