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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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