0

次の形式の CSV ファイルがあります。

Dates,Open,High,Low,Close,Volume
#2010-01-03 15:01:00#,1.1648,1.1648,1.1622,1.1646,8
#2010-01-03 15:02:00#,1.1648,1.1648,1.1648,1.1648,1
#2010-01-03 15:03:00#,1.1648,1.1648,1.1648,1.1648,2

編集:明確にするために、それはYYYY-MM-DD.

次のスクリプトを使用してAccess 2010にインポートすると( にありますD:\Data\Processed):

Dim strFolderPath As String
strFolderPath = "D:\Data\Processed\"
Dim StrFile As String
StrFile = Dir(strFolderPath & "*.txt")

Do While Len(StrFile) > 0
    'MsgBox (objF1.Name)
    DoCmd.TransferText acImportDelim, , StrFile & "draft", strFolderPath & StrFile, True
    'DoCmd.TransferText acImportDelim, strFolderPath & objF1.Name, False
    'DoCmd.TransferText acImportDelim, "TextImportSpecs", "tblImportedFiles", strFolderPath & objF1.Name, False
    'DoCmd.TransferText _
    'TransferType:=intImportType, _
    'SpecificationName:=strSpecification, _
    'TableName:=strTable, _
    'FileName:=strPath & strFile, _
    'HasFieldNames:=blnHasFieldNames
    'strFile = Dir
    Name strFolderPath & StrFile As "D:\Data\Done\" & StrFile 'Move the files to the archive folder
    StrFile = Dir
Loop

最初のフィールドを日付ではなく文字列としてインポートします。テキスト ファイルの形式を変更するか (推奨)、日付/時刻オブジェクトとしてインポートできるようにスクリプトを変更していただければ幸いです。

4

1 に答える 1

1

データ ファイルからシャープ記号 ('#' と呼んでいますか?) を削除してみてください。

DoCmd.TransferTextメソッドを介して CSV データをインポートしてテーブルを作成すると、Access (Jet) は、インポートされたデータの最初の行のスキャンで見つかったデータに基づいて、列のデータ型を割り当てることをご存知だと思います。列に数値データがある場合、Jet はその列にNumberデータ型を割り当て、日付形式のデータはDateTime列を 取得します。

あなたの場合、Jetは「#」文字のために「Dates」列のデータ型を特定できなかったため、その列に(かなり一般的な)Textデータ型を割り当てました。

于 2013-05-11T07:31:57.407 に答える