将大文件上传到 Microsoft Access

Upload large file to Microsoft Access

我对设置 MS Access 数据库还很陌生。只是想知道是否有办法上传超过 150 万行的逗号分隔文件并忽略前 3 行(文件 header)和最后一行(页脚)。 此文件内容的 header 在第 4 行。

最后我自己解决了。 页眉和页脚的列数不同。 我使用行输入语句来检查我的文本文件的每一行。 这是我的代码:

Sub FileUpload_CMP_Funding()

Dim sFile, sText As String
Dim dText As Variant
Dim db As Database
Dim rst As Recordset2
Dim i As Long

sFile = "C:\NotBackedUp\testfile\CMPFUNding.out"
Open sFile For Input As #1
Do While Not EOF(1)
    Line Input #1, sText
        dText = Empty
        dText = Split(vText(i), ",")
        'My main content has 24 columns 
        If UBound(dText) - LBound(dText) + 1 = 24 Then
            If dText(0) <> "Product ID" Then 'skip the header row at the 4th rows

                Set db = CurrentDb
                Set rst = db.OpenRecordset("tblCMP_Funding", dbOpenDynaset)
                rst.AddNew
                rst!ProductID = Trim(Replace(dText(0), """", ""))
                rst!FundID = Trim(Replace(dText(1), """", ""))
                ""
                'Update whatever field is required to be updated
                rst.Update
                Set db = Nothing
                Set rst = Nothing
            End If
        End If
Loop
Close #1

End Sub  

希望对有相同需求的朋友有所帮助