Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Use relative address for database query

I used a query in Excel to link to an Access query.
The problem is that when I moved the files to a new folder, I could no
longer refresh the external data (excel was still looking for the *.mdb file
in the old folder). Is it possible to use a relative location for the db
file, instead of an absolute location? It will always be in the same folder
as the excel file.

Thanks,
~ Horatio
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Use relative address for database query

hi
the file path to the access query is hard coded into the sql of the excel
query.
you must change the file path to the new location.
but from my experience and from a number of posts to this forum, changing
the file path in the sql doesn't seem to work as expected. the excel query
still points at the old location.
so i always just delete the old query in excel and create a new query for
the new location.
yeah, i know. sucks. so my best advise is to have someone spank your hands
everytime you get into the mood of moving something.

Regards
FSt1

"Horatio J. Bilge, Jr." wrote:

I used a query in Excel to link to an Access query.
The problem is that when I moved the files to a new folder, I could no
longer refresh the external data (excel was still looking for the *.mdb file
in the old folder). Is it possible to use a relative location for the db
file, instead of an absolute location? It will always be in the same folder
as the excel file.

Thanks,
~ Horatio

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Use relative address for database query

Thanks for the advice.


"FSt1" wrote:

hi
the file path to the access query is hard coded into the sql of the excel
query.
you must change the file path to the new location.
but from my experience and from a number of posts to this forum, changing
the file path in the sql doesn't seem to work as expected. the excel query
still points at the old location.
so i always just delete the old query in excel and create a new query for
the new location.
yeah, i know. sucks. so my best advise is to have someone spank your hands
everytime you get into the mood of moving something.

Regards
FSt1

"Horatio J. Bilge, Jr." wrote:

I used a query in Excel to link to an Access query.
The problem is that when I moved the files to a new folder, I could no
longer refresh the external data (excel was still looking for the *.mdb file
in the old folder). Is it possible to use a relative location for the db
file, instead of an absolute location? It will always be in the same folder
as the excel file.

Thanks,
~ Horatio

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 135
Default Use relative address for database query

I came up with a solution.
I wrote the query as a macro (using macro recorder for help). Then I used
the workbook path where needed in the query, since the workbook path and the
database path will always be the same. It looks like this:

Sub Query_1()
Dim sPath As String
sPath = ThisWorkbook.Path

With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;" & _
"DBQ=" & sPath & "\MyDB.mdb;" & _
' etc... I went through the query code, and
' inserted sPath into the code wherever needed,
' just like the "DBQ=..." line above.
'
End With
End Sub


"FSt1" wrote:

hi
the file path to the access query is hard coded into the sql of the excel
query.
you must change the file path to the new location.
but from my experience and from a number of posts to this forum, changing
the file path in the sql doesn't seem to work as expected. the excel query
still points at the old location.
so i always just delete the old query in excel and create a new query for
the new location.
yeah, i know. sucks. so my best advise is to have someone spank your hands
everytime you get into the mood of moving something.

Regards
FSt1

"Horatio J. Bilge, Jr." wrote:

I used a query in Excel to link to an Access query.
The problem is that when I moved the files to a new folder, I could no
longer refresh the external data (excel was still looking for the *.mdb file
in the old folder). Is it possible to use a relative location for the db
file, instead of an absolute location? It will always be in the same folder
as the excel file.

Thanks,
~ Horatio

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a database query that does not reference an IP address. Brady Excel Discussion (Misc queries) 0 July 12th 07 07:13 PM
database query not showing foxpro database How I import data mangat New Users to Excel 1 June 24th 07 03:31 PM
How do I avoid excel change absolute address to relative address Miguel Excel Discussion (Misc queries) 3 May 10th 07 11:18 PM
what is difference between absolute address and relative address? what is difference between absolute addr Excel Discussion (Misc queries) 1 July 22nd 06 08:17 AM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 05:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"