I have created an ODBC connection to an Access DB for data retrieval to an
excel file. All was working great, but now I have to move the Access DB to
another location on the server. I changed the ODBC connection in the control
panel to point to the newly located database, but Excel is still looking for
the old location.
What should I do?
Help appreciated.
Phil
1) Create/Open a query in MS-Query. Go to Edit|Options. Make sure
'Qualify table names in SQL statement' is UNCHECKED. Press [OK]. From this
point on, any queries created with MS-Query (directly or indirectly via
Excel) will not include the path to the actual DB in your SQL. You'll now
have to re-create any queries in Excel to make sure the path to your Access
DB is no longer included in your queries.
2) Create some code to fire on the 'Open' event of your work book. The
code below is what I used. You'll probably have to modify it a bit for your
case, as mine only deals with pivot tables that use external data:
Private Sub Workbook_Open()
Dim ws As WorkSheet
Dim pt As PivotTable
Dim dbPath As String
On Error Resume Next
For Each ws In ActiveWorkbook.Sheets
For Each pt In ws.PivotTables
'For me, my Access Db is always in the same directory
' as my spreadsheet, this may be different for you
dbPath = ActiveWorkbook.Path
'Make sure the path ends in '\'
If Right( dbPath, 1) <> "\" Then
dbPath = dbPath + "\"
End If
'My ODBC DSN is called AggInd32, and
' must be set up on any machine using this spreadsheet
'My Access Db is called 'AggInd32.mdb'
pt.PivotCache.Connection = "ODBC;DSN=AggInd32;DBQ=" & dbPath &
"AggInd32.mdb"
Next pt
Next ws
End Sub
You'll probably using the QueryTable(s) objects rather than the
PivotTable(s) objects, but the approach will be similar.
*Note: Assumes you're using the version of MS Query that comes with Office
2000 (rather than '97)
"Phil Atkinson" <ph...@firstenergy.no> wrote in message
news:9m5gda$lsj$1...@oslo-nntp.eunet.no...
Instead of:
pt.PivotCache.Connection = "ODBC;DSN=AggInd32;DBQ=" & dbPath &
"AggInd32.mdb"
you could use:
pt.PivotCache.Connection = "ODBC;DSN=AggInd32"
This will force excel to find the DB whereever your ODBC DSN is pointing to.
This was not feasible for me since the DB may be in another location for me.
Excel '97 needed the ODBC stuff to work though, so I couldn't leave it out
since my spreadsheet needs to work in Excel 97 and 2000. With Excel 2000,
you can connect with OLEDB, and do without any ODBC:
pt.PivotCache.Connection = "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & dbPath & "aggind32.mdb"
"Chris Pettingill" <ChrisPe...@Compuserve.Com> wrote in message
news:#W0btaXMBHA.1676@tkmsftngp05...
I've the same problem with multiple Pivot tables in Excel '97 workbook, using
data from Access '97 DB. I just want to be able to move, copy or rename the
directory where I put the .xls and .mdb files, just like you.
I tried the script you suggest and it's still not working. Is it because of MS
Query version ? If so, how can I upgrade MS Query or ODBC driver without
upgrading to Office 2000 ?
Patrick.
Chris Pettingill a écrit :
"Patrick Enoux" <patric...@francetelecom.com> wrote in message
news:3BA0E1F8...@francetelecom.com...
how can you get to the embedded hardcoded path in excel and change it?
"Chris Pettingill" <ChrisPe...@Compuserve.Com> wrote in message
news:#W0btaXMBHA.1676@tkmsftngp05...
Basically, you need to do the same thing as I'm doing with one change.
Instead of the line:
' Overrides the ODBC DB path
pt.PivotCache.Connection = "ODBC;DSN=AggInd32;DBQ=" &_
dbPath & "AggInd32.mdb"
Use:
' Causes Excel to refresh the settings from the AggInd32 ODBC alias
' including any path changes.
pt.PivotCache.Connection = "ODBC;DSN=AggInd32;"
This forces Excel to reload the parameters of the ODBC alias 'AggInd32'
including any new directory path. Unlike my 1st version, I'm not overriding
the db path specified by ODBC.
"Scott" <salex...@msn.com> wrote in message
news:eNJ4wIKPBHA.1548@tkmsftngp03...