XL: OpenDatabase Method Prompts for User Input

Last reviewed: March 13, 1998
Article ID: Q141826
The information in this article applies to:
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows

SYMPTOMS

In Microsoft Excel, when you run a macro that uses the OpenDatabase method to open a database, you may be prompted for information even though the Source argument includes a complete connection string to the data source you are using.

CAUSE

If either the Exclusive (called to Options in version 97) and Read-only arguments are omitted, and the Source argument is included, you will be prompted for any information needed to connect to a data source. The following example illustrates this behavior.

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Before you run the macro, you must create a reference to the DAO Object Library. To do this, activate a module sheet, click References on the Tools menu and select Microsoft DAO 3.5 Object Library (3.0 Object Library in version 7.0).

Sub OpenDB()
    Dim db As Database

    ' Open a connection to the SQL Server data source called
MySQLServer
    Set db = OpenDatabase("", , , "ODBC;DSN=MySQLServer;" _
             & "UID=user1;PWD=pass;DATABASE=Master")
End Sub

In this example, all necessary options to make a connection to the data source called MySQLServer have been specified. However, because the Exclusive (or Options) and Read-only options are missing, you will be prompted for the connection information anyway.

RESOLUTION

When you use the Source argument of the OpenDatabase method, specify a value of True or False for both the Exclusive (Options) and Read-only arguments.

The example above would then read as:

Sub OpenDB()
    Dim db As Database

    ' Open a connection to the SQL Server data source called MySQLServer
    Set db = OpenDatabase("",False ,False , "ODBC;DSN=MySQLServer;" _
             & "UID=user1;PWD=pass;DATABASE=Master")
End Sub

STATUS

This behavior is by design.

MORE INFORMATION

Microsoft Excel Help for the OpenDatabase method states the following for the Source argument:

   You must supply the exclusive and read-only arguments to supply a
   source string.

REFERENCES

For more information about the OpenDatabase method, click Index tab in Help, type the following text

   OpenDatabase method

and double-click the selected text to go to the "Retrieving external data" topic.


Additional query words: 7.00 8.00 97
Keywords : kbcode kbprg xlwin
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.