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

正しいのは 2 番目だけです。どうして?!?!追加しますか?!?

4

1 に答える 1