Microsoft KB Archive/141826

= OpenDatabase Method Prompts for User Input =

Article ID: 141826

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition

-



This article was previously published under Q141826





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 programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. 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.

