Search code examples
ms-accessms-access-2013

Parsing a txt file in MS access 2013


I have a fixed with txt file that I am trying to parse based on data in a certain position.

I need to loop through the recordsets an have it append into a table.

I am having a problem trying to parse out the initial txt file.

I am using where Mid("AllData", 1, 2) = "BR"

I have the code below. What am I doing wrong?

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

Solution

  • Try this:

    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