MSQuery: Obtaining Login String from DDE Request to Query

Last reviewed: September 2, 1997
Article ID: Q105953
The information in this article applies to:
  • Microsoft Query for Windows, version 1.0
  • Microsoft Query for Windows 95, version 2.0
  • Microsoft Query 97 for Windows
  • Microsoft Excel for Windows, verison 5.0
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows

SUMMARY

To automate the querying process between Microsoft Query and another program, you can create a macro that logs into a data source from within Microsoft Query. To do this, the macro must have the correct connection string. You can obtain this connection string from an existing query through a dynamic data exchange (DDE) channel to the query.

MORE INFORMATION

To obtain the connection string required by the Microsoft Query, call ODBCLOGON by initiating a DDE session to a query that is currently logged into a data source and perform a DDE request of the connectionstring item:

  1. Start Microsoft Query and log on to a data source.

  2. In Microsoft Query, create a query (QUERY1).

  3. Start Microsoft Excel and create one of the following macros.

Visual Basic Code Example

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.

   Sub get_connection()

      ' Open a DDE channel to MSQuery and return the channel number
      chan = Application.DDEInitiate("Msquery", "Query1")
      ' Return the array that contains the connection string
      connect = Application.DDERequest(chan, "ConnectionString")
      ' Terminate the DDE channel
      Application.DDETerminate chan

   End Sub

The DDERequest method returns the array "connect" that contains a valid connection string that can be used by the ODBCLOGON command in order to connect through a DDE control.

NOTE: If you are using Microsoft Query 97, you must modify the line that initiates the DDE channel. This line must include the correct name for the query. In Microsoft Query 97, the query name is similar to "Query 1 from <Data Source Name>." For example, if the data source that the query uses is named "My DataSource," change the DDEInitiate line to the following:

   chan = Application.DDEInitiate("Msquery", "Query 1 from My DataSource")

Microsoft Excel Version 4.0 Macro Example

Microsoft provides macro examples 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. This macro is provided as is and Microsoft in no way guaranties that the following code can be used in all situations and will not support modifications of the code to suit specific customer requirements.

   =SET.NAME("CHAN",INITIATE("MSQUERY","QUERY1"))
   =SET.NAME("Connect",REQUEST(CHAN,"CONNECTIONSTRING"))
   =TERMINATE(CHAN)
   =RETURN()

The defined name CONNECT will contain a valid connection string that can be used by the ODBCLOGON command in order to connect through a DDE control.

NOTE: If you are using Microsoft Query 97, you must modify the line that initiates the DDE channel. This line must include the correct name for the query. In Microsoft Query 97, the query name is similar to "Query 1 from <Data Source Name>." For example, if the data source that the query uses is named "My DataSource," change the DDEInitiate line to the following:

    =SET.NAME("CHAN",INITIATE("MSQUERY","Query 1 from My DataSource"))

REFERENCES

"Microsoft Query User's Guide," pages 134-144

For more information about the DDERequest Method, click the Search button in Visual Basic Reference Help and type:

   DDERequest Method


Additional reference words: 1.00 2.00 5.00 7.00 8.00 97 xl97
Keywords : IntpDde kbprg kbtool kbusage
Version : 1.00 2.00 97
Platform : WINDOWS


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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.