#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default ODBC error


Hi all.

I'm trying to dynamically direct some XL QueryTables to the 'correct' MS
Access database (local on C:\ , or on network drive).

The XL file with the QueryTables may be executed either on a network drive
or on my hard drive.

To achieve this, i'm constructing the full path name to the Access database
based on ThisWorkbook.Path.

So depending on which version of the XL file is being executed (network or
local), the variable that holds the path to the Access database
(strAppAccFullName) is constructed accordingly.

Then i'm using this variable (strAppAccFullName) to define the ODBC string
of the QueryTables.

***

Dim strConnODBC As String
Dim QryTbl as QueryTable

' By dynamically re-creating this string each time, we ensure that the
XL queries
' are directed to the correct database (local or online).
' Note that the DB path is included in the string as a variable
(strAppAccFullName).

strConnODBC = _
"ODBC;" _
& "DSN=MS Access Database;" _
& "DBQ=" _
& strAppAccFullName & ";" _
& "DefaultDir=" _
& strAppAccFullName & ";" _
& "DriverID=25;" _
& "FIL=MS Access;" _
& "MaxBufferSize=2048;" _
& "PageTimeout=5;"

intCnt = 0
For Each ws In ThisWorkbook.Worksheets
intCnt = intCnt + 1
ws.Activate

Set QryTbl = ActiveSheet.QueryTables(1)
With QryTbl
.Connection = strConnODBC
.Refresh BackgroundQuery:=False
End With
Set QryTbl = Nothing
Next

***

The problem is i get an error when i run the local XL (the network XL runs
ok).
The error is: 1004 - General ODBC error.

The funny thing is that when i manually redirect a specific QueryTable that
generates an error to the 'correct' Access database, and then compare the
Connection string of the 'adapted' QueryTable with what is generated above,
the strings are identical...

Any insights / tips on this one?

Many thanks,
Alex


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default ODBC error


Forget it, the logic described in the example works...

My mistake was that I was just using different versions of Access files that
had some differences in field names, which caused the QueryTables to get
confused...


"alexhatzisavas" wrote:


Hi all.

I'm trying to dynamically direct some XL QueryTables to the 'correct' MS
Access database (local on C:\ , or on network drive).

The XL file with the QueryTables may be executed either on a network drive
or on my hard drive.

To achieve this, i'm constructing the full path name to the Access database
based on ThisWorkbook.Path.

So depending on which version of the XL file is being executed (network or
local), the variable that holds the path to the Access database
(strAppAccFullName) is constructed accordingly.

Then i'm using this variable (strAppAccFullName) to define the ODBC string
of the QueryTables.

***

Dim strConnODBC As String
Dim QryTbl as QueryTable

' By dynamically re-creating this string each time, we ensure that the
XL queries
' are directed to the correct database (local or online).
' Note that the DB path is included in the string as a variable
(strAppAccFullName).

strConnODBC = _
"ODBC;" _
& "DSN=MS Access Database;" _
& "DBQ=" _
& strAppAccFullName & ";" _
& "DefaultDir=" _
& strAppAccFullName & ";" _
& "DriverID=25;" _
& "FIL=MS Access;" _
& "MaxBufferSize=2048;" _
& "PageTimeout=5;"

intCnt = 0
For Each ws In ThisWorkbook.Worksheets
intCnt = intCnt + 1
ws.Activate

Set QryTbl = ActiveSheet.QueryTables(1)
With QryTbl
.Connection = strConnODBC
.Refresh BackgroundQuery:=False
End With
Set QryTbl = Nothing
Next

***

The problem is i get an error when i run the local XL (the network XL runs
ok).
The error is: 1004 - General ODBC error.

The funny thing is that when i manually redirect a specific QueryTable that
generates an error to the 'correct' Access database, and then compare the
Connection string of the 'adapted' QueryTable with what is generated above,
the strings are identical...

Any insights / tips on this one?

Many thanks,
Alex


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
I have Error 1919 Error Configuring ODBC dataSource Database Texanna1 Excel Discussion (Misc queries) 1 September 12th 06 06:35 AM
Run-time error 1004 - General ODBC Error Linda Excel Programming 0 July 5th 06 04:32 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Runtime error '1004' General ODBC error star_lucas New Users to Excel 0 August 29th 05 04:09 PM
Run time error '1004': Generaol ODBC error Dwaine Horton[_3_] Excel Programming 2 April 26th 05 02:52 PM


All times are GMT +1. The time now is 10:20 PM.

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

About Us

"It's about Microsoft Excel"