Allows a program to connect to a data source. You can specify whether dialog boxes are presented to the user at logon time. This command is available only on the system channel.
Syntax
ODBCLogon(connectstring, dialog)
connectstring A string that supplies information (such as the data source name, user ID, and password) required by a driver to connect to a data source. This argument must follow the format required by the driver you're using. (For more information about the connection string, see the documentation for your data source.)
Note Because Microsoft Query supports File Data Source Names (DSNs), you can use the ConnectionString request item to obtain the DSN-less connection string of a query created from a File DSN. You can then use that connection string to reconnect to the data source from any computer.
dialog Determines whether dialog boxes are displayed at logon time. Can be one of the following values.
Value | Description |
---|---|
0 (zero) | No dialog boxes are displayed. |
1 | Dialog boxes are displayed to obtain additional information from the user not provided by the connection string. |
2 | Dialog boxes are displayed with values from the connection string filled in as default values. |
3 | Same as 1, except that information not required to connect to the data source appears dimmed. |
Example
This example uses the ConnectionString request item to return the string needed to connect with a data source. The example saves the string after the user logs onto a data source, and later uses the ODBCLogon command to connect to the same data source without user input.
connstr = DDERequest(chan, "ConnectionString")
' intervening code
DDEExecute chan, "[ODBCLogon (connstr(1), 0)]"