Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

ODBC error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alexhatzisavas - 25 Jan 2007 13:04 GMT
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
alexhatzisavas - 25 Jan 2007 13:37 GMT
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...

> Hi all.
>
[quoted text clipped - 65 lines]
> Many thanks,
> Alex
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.