Reading text (.txt) files from with Microsoft Access

The following is sample VBA code for reading a text file from within Microsoft Access.  Note that this is but a few lines of a five hundred line routine of importing a file which has about fifteen different types of lines.

Dim Alpha1 As Variant, Alpha2 As Variant, Alpha3 As Variant
Dim Alpha4 As Variant, Alpha5 As Variant, Alpha6 As Variant
Dim Numeric1 As Variant, Numeric2 As Variant, Numeric3 As Variant
Dim Numeric4 As Variant, Numeric5 As Variant, Numeric6 As Variant
Dim strInputFileName As String

Open strInputFileName For Input As #1
Do While Not EOF(1) ' Loop until end of file.

    ' Acorn, Isometric, Isometric Revision, Spool, Acorn Revision ,PipeSpec
    '"00001","FDM-044-21LC2042","1A","2044-21LC2042-A",0,"CS"
    Input #1, Alpha1, Alpha2, Alpha3, Alpha4, Numeric5, Alpha6
    ' do something with fields

    ' Dia-Ins, Weight, ?, Spool Drawer Initials, Date, ?
    '35,606.0635,681,"DA","07-28-1999",0
    Input #1, Numeric1, Numeric2, Numeric3, Alpha4, Alpha5, Numeric6
    ' do something with fields again

Loop

Close #1

 [ Access | Main ]