Using Excel VBA to Identify Access dB Root File Folder

psulions83

Board Regular
Joined
Nov 16, 2015
Messages
127
Hi,

Is there a way with the below code to use a simple line to access my access file. The access file is in the same location as the Excel workbook I am running this from and will always have the same filename. The below works as is. I just want to be able to copy this into new locations and not update the code each time. Any help would be much appreciated.


Sub delete()


Dim appAccess As Access.Application


Set appAccess = New Access.Application


appAccess.OpenCurrentDatabase "C:\Access\Database1.accdb"

appAccess.Visible = True

Application.DisplayAlerts = False

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

MsgBox "Delete Tables Complete. Compact & Repair Database in Access", vbCritical

End Sub
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You can get the path for the workbook the code is in using ThisWorkbook.Path.
Code:
appAccess.OpenCurrentDatabase ThisWorkbook.Path & "\Database1.accdb"
 
Upvote 0
If I understand correctly:

Code:
[B]appAccess.OpenCurrentDatabase ThisWorkbook.Path & "\Database1.accdb" [/B]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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