0

有人可以帮助我理解为什么,当我运行此代码时,每次在数据范围内我们有 Kpi1-2 > 24H 的记录时,我都会检索到错误的结果(示例表是 25K 记录的提取)。

在此处输入图像描述

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

DBPath = ThisWorkbook.FullName
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
        "Extended Properties=""Excel 8.0;HDR=Yes;"";"    

Strsql:Select [DataAttesa] as Data, avg([Kpi1-2]) as nr FROM [db_In$] Where TypeTrasp  = 'STD' and [1-2_ESITO] in ('90%','100%','Out of Time','On Going') group by [DataAttesa] Order by [DataAttesa]asc

    objRecordset.Open strsql, objConnection, adOpenStatic, adLockReadOnly, adCmdUnspecified
       Do Until objRecordset.EOF
         debug.print objRecordset.Fields.item("nr")
         objRecordset.MoveNext
      Loop
    objRecordset.Close

更新:我测试这段代码:

debug.print objRecordset.Fields.item("nr")
in the immediate windows I see: 21/01/1900  11:41:00
if I test tu put the result into a cell:

Cells(20, 7) = objRecordset.Fields.item("nr") 
the cells.value will be 22/01/1900  11:41:25
Cells(21, 7) = Format(objRecordset.Fields.item("nr"), "dd/mm/yyyy hh:mm;@")
the cells.value will be 21/01/1900  11:41:25

只有第二个是正确的。为什么?!?!哇追加?!?

4

1 回答 1

0

这篇文章讨论了这个问题的解决方案: Difference time view from Excel to VBA

如果它可以帮助任何其他用户,我插入链接

法布里齐奥

于 2019-03-15T15:30:55.013 回答