XL: OpenDatabase Method Prompts for User InputLast reviewed: March 13, 1998Article ID: Q141826 |
The information in this article applies to:
SYMPTOMSIn 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.
CAUSEIf 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 calledMySQLServer Set db = OpenDatabase("", , , "ODBC;DSN=MySQLServer;" _ & "UID=user1;PWD=pass;DATABASE=Master") End SubIn 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.
RESOLUTIONWhen 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 STATUSThis behavior is by design.
MORE INFORMATIONMicrosoft 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. REFERENCESFor more information about the OpenDatabase method, click Index tab in Help, type the following text
OpenDatabase methodand double-click the selected text to go to the "Retrieving external data" topic.
|
Additional query words: 7.00 8.00 97
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |