Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel 2007: OpenDatabase fails to connect to a SQL database

Excel 2007: OpenDatabase fails to connect to a SQL database

Excel 2007: OpenDatabase fails to connect to a SQL database

I have a problem with my excel add-in which works fine for earlier versions of excel - but does not work properly with excel 2007. The OP system is windows XP.

The code to connect is as follows:
Public cs_dbs As Database
Set cs_dbs = OpenDatabase(dbName, False, True, "ODBC;Regional=Yes")

When dbName is empty, the user will be prompted to select an ODBC source. After I select the source I get the following error message: Cannot open MyDB database. Error: ODBC--connection to 'MyDBSQL2005' failed.

If I look in the odbc trace log, I will eventually see the following error: DIAG [S1000] [Microsoft][ODBC Driver Manager] General error: invalid window handle.

Trying to connect to a Progress database, also ends in failure after I select an odbc source. In this case I should see a window prompting me for a password but I just get the error message that the operation was cancelled by the user.

The following will work:
Public cs_dbs As Database
Set cs_dbs = OpenDatabase(dbName, False, True, "ODBC;Regional=Yes")

In debug mode, I can connect to both DB types. The odbc trace logs show no errors.

Does anybody have any clue what is going wrong here? I hope I have provided enough information.

RE: Excel 2007: OpenDatabase fails to connect to a SQL database

I think that you need a reference to a DAO library. tools > References in the VB Editor.


glasses When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Largetongue

RE: Excel 2007: OpenDatabase fails to connect to a SQL database

I have a reference to the Microsoft DAO 3.6 Object Library.
Could I be missing other references? But I'd probably get an error message when compiling the add-in.
It could be a bug in Excel 2007. This add-in works in earlier versions of excel and works in debug mode in excel 2007.
AND if I open an existing excel sheet which already uses the add-in, then I can connect without problems to the database. The DB is opened automatically & formulas are refreshed.

Only with a new/blank sheet will the connection fail.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close