Connection String Relative Reference Requiring DSN

Juglaz

Board Regular
Joined
Jul 2, 2013
Messages
177
Hi guys,

I've got a workbook that pulls data from an access database. MS Query created the following connection string which works just fine:

DBQ=C:\Users\t5264ab\Desktop\Dashboard\Claim Analyzer Total 13MY YTD.mdb;DefaultDir=C:\Users\t5264ab\Desktop\misc docs;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;</SPAN>

However I need the paths to be relative and point to a file located in the same folder as the workbook. I used ThisWorkbook.Path:

DBQ=" & ThisWorkbook.Path & "Claim Analyzer Total 13MY YTD.mdb;"DefaultDir=" & ThisWorkbook.Path &;"Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;

After making this change, when Excel goes to refresh the data it gives me a pop-up to Select Data Source. I don't understand why I suddenly need a DSN with a relative reference. Can somebody please help? Thanks.
</SPAN>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Possibly just try:
DBQ=" & ThisWorkbook.Path & "\" & ...

The path property doesn't provide the trailing separator that you need.
 
Upvote 0
Possibly just try:
DBQ=" & ThisWorkbook.Path & "\" & ...

The path property doesn't provide the trailing separator that you need.

Still getting the same request for a Data Source. That may have been one of multiple errors in my code though.
 
Upvote 0
Is this something you are doing in a macro?
 
Upvote 0
Is this something you are doing in a macro?

No macros. Just trying to get the connection string right.
The string shown leads to the Select Data Source dialogue box. With the absolute reference path it didn't need a DSN.

S90DtR5.png
 
Upvote 0
Hi,
Sorry - no can do. You can't use ThisWorkbook.Path as a dynamic variable in the dialog. I think all you can do is either set it with vba or allow the user to select it when the popup comes up.
ξ
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,179
Members
448,948
Latest member
spamiki

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