Using Excel VBA to Identify Access dB Root File Folder

psulions83

Board Regular
Joined
Nov 16, 2015
Messages
126
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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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