XL7: Get External Returns Incorrect Data and/or Blank RowsID: Q158835
|
When you use the Get External Data command on the Data menu to return data from an external data source, the data that is returned is not correct. Some fields or rows that should contain data are blank; or some fields or rows contain incorrect data.
This problem may occur when Microsoft Excel uses the Microsoft Query
dynamic data exchange (DDE) Fetch command to return the data to the
worksheet.
This problem occurs only under Windows 95. The problem does not occur when
you use Microsoft Windows NT 3.51 or later.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. The problem has been corrected in Microsoft Excel 97 for Windows.
For additional information on using DDE with Microsoft Query, please see
the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: <LINK TYPE="ARTICLE" VALUE="Q149581">Q149581</LINK>
TITLE : How to Retrieve Request Items Using DDERequest to MSQuery
ARTICLE-ID: <LINK TYPE="ARTICLE" VALUE="Q142357">Q142357</LINK>
TITLE : XL: Visual Basic Example Using BuildSQL
ARTICLE-ID: <LINK TYPE="ARTICLE" VALUE="Q105953">Q105953</LINK>
TITLE : MSQuery: Obtaining Login String from DDE Request to Query
Sub GetDataUsingDAO()
'Open the database.
Set Db = opendatabase("c:\my documents\db1.mdb")
'Create a recordset using a SQL statement.
Set RS = Db.OpenRecordset("Select * from Table1")
'Copy the field names starting at Sheet1!A1.
For i = 1 To RS.Fields.Count
Range("Sheet1!A1").Offset(, i - 1) = RS(i - 1).Name
Next
'Copy the results starting at Sheet1!A2.
Range("Sheet1!A2").CopyFromRecordset RS
Db.Close
End Sub
Sub GetDataUsingDDE()
Dim chan As Integer
Dim r As Variant, c As Variant
Dim StartCell As Range
Dim RowsToRetrieve As String
Dim i As Integer
'Activate query - if it is not running, an error occurs and the
'error handler StartQuery will start Query.
On Error GoTo StartQuery
AppActivate "Microsoft Query"
On Error GoTo 0
'Initiate a channel to query and return control to the user.
chan = DDEInitiate("MSquery", "system")
DDEExecute chan, _
"[UserControl('&Return Data To Microsoft Excel', 3, true)]"
'Prompt the user for the cell to return the data to.
Set StartCell = Application.InputBox( _
prompt:="Select the starting cell", Type:=8)
'Obtain the number of rows and columns in the result.
r = DDERequest(chan, "NumRows")
c = DDERequest(chan, "NumCols")
'Return the headers to the first row at the starting cell.
DDEExecute chan, "[Fetch('Excel','" & StartCell.Worksheet.Name & _
"','" & StartCell.Resize(, c(1)).Address( _
ReferenceStyle:=xlR1C1) & "','R1:R1/Headers')]"
'Return the data to the worksheet 100 rows at a time.
For i = 1 To r(1) Step 100
RowsToRetrieve = "R" & i & ":R" & i + 100 - 1
DDEExecute chan, "[Fetch('Excel','" & StartCell.Worksheet.Name _
& "','" & StartCell.Offset(i).Resize(100, c(1)).Address( _
ReferenceStyle:=xlR1C1) & "','" & RowsToRetrieve & "')]"
DoEvents
Next
'Terminate the channel.
DDETerminate chan
Exit Sub
StartQuery:
Shell "c:\program files\common files\microsoft shared" & _
"\msquery\msqry32.exe", 2
DoEvents
Resume
End Sub
For i = 1 To r(1) Step 100
For more information about Data Access Objects, click the Index tab in
Microsoft Excel Help, type the following text
data access, using
Additional query words: garbage character gap missing XL7 nothing nil nada
Keywords : kbtool xlvbainfo xlquery xldao
Version : WINDOWS:7.0,7.0a,95
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: June 24, 1999