Connection String In Excel

mfosterla

New member
Local time
Today, 15:29
Joined
Apr 16, 2008
Messages
1
I have an Excel workbook and Access Database that are going to be moved around a lot but always in the same directory. I have a Database Connection String in the Excel workbook as follows:

DSN=MS Access Database;
DBQ=C:\Databases\MCD.mdb;
DefaultDir=C:\Databases;
DriverId=25;
FIL=MS Access;
MaxBufferSize=2048;
PageTimeout=5;

I want to set DBQ and DefaultDir to be the current workbook path. I know I can use ThisWorkbook.Path using VBA. But, How can I accomplish this in the connection string under connection properties?

Thanks,

Mark Foster
 
Hi Mark,

if you are using an ADODB connection object, do this (where conn is the Connection object) or set the connection string:
Code:
conn.ConnectionString = "DSN=MS Access Database;DBQ=" & thisworkbook.path & "\MCD.mdb;
DefaultDir=" & thisworkbook.path & ";
DriverId=25;
FIL=MS Access;
MaxBufferSize=2048;
PageTimeout=5;"

HTH,
Chris
 

Users who are viewing this thread

Back
Top Bottom