external data file locations

L

Lou Sanderson

Windows XP, Office 2003

I use Access to build all my queries, and use 'get external data' to get the
data and build charts in Excel. As such, if I move the location of my Access
database, Excel gives me an error saying it cant find the file.

Does anyone know how I can move the Access database and then tell excel the
new location or something like that so it all still works?

Thanks,
Lou Sanderson
 
K

K Dales

A quick way:
In VBA editor immediate pane, ?
Worksheets("SheetName").QueryTables(1).Connection shows the connection
string; for Access normally this will include in it the path to the Access
file. Use the Replace function to replace this with the new file path, e.g:
Worksheets("SheetName").QueryTables(1).Connection=Replace(Worksheets("SheetName").QueryTables(1).Connection ,"C:\old path\file.mdb","C:\new path\file.mdb")

sorry about any word wrapping: the above should all be one long line
 
A

Ardus Petus

You'll have to update Connection and CommandText attributes of the
querytable:

'------------
Sub ModQuery()
Const oldpath = "U:\Databases\mydatabase"
Const newpath = "C:\mydatabase"
Dim qt As QueryTable
Set qt = ActiveSheet.QueryTables(1)
With qt
.Connection = Replace(.Connection, oldpath, newpath)
.CommandText = Replace(.CommandText, oldpath, newpath)
End With
End Sub
'-----------

HTH
 
L

Lou Sanderson

K Dales,

OK, this changed the location of the "DBQ" (whatever that is) in the
connection string to the correct new location, but the "DefaultDir" remains
at the old location, and my error still exists....

Do I need to change the "DefaultDir" location as well, and if so can I have
help with that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top