Microsoft KB Archive/147217

= MSQuery: DDE Activate Command Does Not Activate Window =

Article ID: 147217

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Query 2000

-



This article was previously published under Q147217



SYMPTOMS
When you use the Microsoft Query DDE command, Activate, to activate a query window, the window may not be activated.



RESOLUTION
To work around the problem, close out each query window when you are finished working with it and then create a new one with the OPEN command. The following macro is an example of using this method.

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 Product Support Services (PSS) professionals 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.

To run the macro do the following:

 Start Microsoft Query. Create a data source with the name NWind, using the dBASE files included with Microsoft Excel. In the workbook that contains the macro code, make sure there are two sheets named sheet1 and sheet2.  Type the following procedure: Sub Open_And_Close_Windows Dim chan as integer Dim NumRows As Variant Dim NumCols As Variant

'Initiate a channel to MSQuery. chan = DDEInitiate("MSQuery","System")

'Log on to the NWind datasource. DDEExecute chan, "[Logon('NWind')]"

'Execute a SQL statement. DDEExecute chan,"[Open('Select * From Customer')]"

'Request the number of rows in the data set. NumRows = DDERequest(chan,"NumRows")

'Request the number of columns in the data. NumCols = DDERequest(chan,"NumCols")

'Return the data to sheet1. DDEExecute chan, "[Fetch('Excel', 'Sheet1', 'R1C1:R" _       & NumRows(1) & "C" & NumCols(1) & "', 'All')]"

'Close the current query window. DDEExecute chan, "[Close]"

'Create a new query window. DDEexecute chan, "[Open('Select * From Employee')]"

'Request the number of rows in the data set. NumRows = DDERequest(chan,"NumRows")

'Request the number of columns in the data. NumCols = DDERequest(chan,"NumCols")

'Return the data to sheet2. DDEExecute chan, "[Fetch('Excel', 'Sheet2', 'R1C1:R" _       & NumRows(1) & "C" & NumCols(1) & "', 'All')]"

'Logoff the datasource. DDEExecute chan, "[Logoff('NWind')]"

'Tterminate the channel. DDETerminate chan

End Sub 



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

