Excel VBA to Compact and Repair

psulions83

Board Regular
Joined
Nov 16, 2015
Messages
127
I have seen a lot of threads on compacting and repairing a dB from excel. I have not been able to get anything to work properly.

I have the below code....Is there a way to get the compact and repair to work after I delete the data in my tables?


Sub accessMacro()


Dim appAccess As Access.Application


Set appAccess = New Access.Application


appAccess.OpenCurrentDatabase "FILE LOCATION" 'Location of the Access dB

appAccess.Visible = False

Application.DisplayAlerts = False

appAccess.DoCmd.RunMacro "Mcro_DelTbls" 'Macro to delete the tables in Access dB

appAccess.DoCmd.SetOption "Auto Compact", True 'Compact and Repair after deleting data from tables

appAccess.DoCmd.RunMacro "Mcro_V2" 'Macro to run th

ActiveWorkbook.RefreshAll

appAccess.CloseCurrentDatabase

ActiveWorkbook.Activate


MsgBox "DONE", vbCritical


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Does anyone have any idea on the below? My code is updated to the below but it is not erroring out but it is not compacting the dB.

Code:
Sub delete()

   Dim appAccess As Access.Application


   Set appAccess = New Access.Application
   
   appAccess.OpenCurrentDatabase ThisWorkbook.Path & "\AccessdB"


   appAccess.Visible = True


   Application.DisplayAlerts = False


   appAccess.DoCmd.RunMacro "Mcro_Del"    
   
   appAccess.CommandBars("Menu Bar").Controls("Tools").Controls("Database Utilities").Controls("Compact and Repair Database").accDoDefaultAction
 
   appAccess.CloseCurrentDatabase
   
   'MsgBox "Delete Finished", vbCritical
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,775
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top