在MS Access 2013中解析txt文件

问题描述

我有一个固定的txt文件,我试图根据某个位置的数据进行解析。

我需要遍历记录集并将其追加到表中。

我在解析初始txt文件时遇到问题。

我正在使用其中Mid(“ AllData”,1,2)=“ BR”

我有下面的代码。我在做什么错了?

Sub BR_Records()
On Error GoTo ErrorHandler

Dim strsql As String
Dim rs As DAO.Recordset

strsql = "TBL_AllData"

Set rs = CurrentDb.OpenRecordset(strsql)

With rs
   
    If Not .BOF And Not .EOF Then
           
        .MoveLast
        .MoveFirst
                
        While (Not .EOF)
                    
            Debug.Print rs.Fields("AllData"); where.Mid("AllData",1,2) = "BR"
            
            .MoveNext
            
        Wend
        
    End If
    
    .Close

End With

ExitSub:
    Set rs = nothing

    Exit Sub
ErrorHandler:
    Resume ExitSub
End Sub

解决方法

尝试一下:

With rs   
    If .RecordCount > 0 Then
        .MoveFirst                
        While Not .EOF
            If Mid(.Fields("AllData").Value,1,2) = "BR" Then                    
                Debug.Print .Fields("AllData").Value
            End If
            .MoveNext            
        Wend
    End If
    .Close
End With