ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Relative path in database query connection string (https://www.excelbanter.com/excel-discussion-misc-queries/221739-relative-path-database-query-connection-string.html)

DanL

Relative path in database query connection string
 
I have a connection string that starts out like this:

DSN=Excel Files;DBQ=C:\Folder1\Folder2\Folder3\Filename.xls;

This is an absolute path, but I would like to use a relative path (i.e.
...\Filename.xls without the preceding path) instead. Is this possible?

In this case I am actually using this connection string within the
Filename.xls file. So what I would REALLY like is for the connection string
to refer to the path of the file that is using it. This way, if I save a
copy of the file Filename.xls as Filename2.xls, I don't have to change the
connection string and it will automatically point to Filename2.xls.

joel

Relative path in database query connection string
 
The connection string is a String that you can modfiy like any string (DUH!)

from
Connection = "DSN=Excel Files;DBQ=C:\Folder1\Folder2\Folder3\Filename.xls; "

to
Folder = "C;\Temp\"
Connection = "DSN=Excel Files;DBQ=" & Folder & "Filename.xls;"



"DanL" wrote:

I have a connection string that starts out like this:

DSN=Excel Files;DBQ=C:\Folder1\Folder2\Folder3\Filename.xls;

This is an absolute path, but I would like to use a relative path (i.e.
..\Filename.xls without the preceding path) instead. Is this possible?

In this case I am actually using this connection string within the
Filename.xls file. So what I would REALLY like is for the connection string
to refer to the path of the file that is using it. This way, if I save a
copy of the file Filename.xls as Filename2.xls, I don't have to change the
connection string and it will automatically point to Filename2.xls.



All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com