Importing Text File Into Access Table Format

I have a text file that I am trying to importing into an Access database. The text does follow a structure dut not the best for placing it a table . I have attached an example of what the current text file looks like.

I am trying to get the contents in the text file into a table that has three columns: Student_NM - Student_Major - Student_Class

Is there a way to do this using either VBA or a cmd file that could at least format the data and dump it back into another text file but deliminated?

Any assistance with this would be much appreciated.

Thank you
-textfilexample.txt
LVL 1
spaced45Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TamilvananrajaCommented:
It is very simple process bro,

your text file has ordered content and each row separated by 'vbcrlf'  (Asc(13)).
so, you can use vb6 program as following.

1. Load your Text file into Multiline text Box

for i = 1 to len(text1.text)
if j>=3 then
j=0
end if
if asc(mid$(text1.text, i,1)) <> 13 then

value1 = value1 & mid$(text1.text, i,1)

else
j=j+1
if j = 1 then
res.fields('name') = value1

elseif j=2 then
j=j+1
res.fields('major') = value1

elseif j=3 then
j=j+1
res.fields('class') = value1
endif

Endif


If you know the Vb6 programming you understand be very easy...

if you need real program please let me know and send original text file with some more records.... i will do and attach.

Thanks
0
IrogSintaCommented:
Run this code in a module:
Private Sub ImportMyFile()
    Const strFile As String = "C:\pathToFile\textfilexample.txt"
    Dim strLine As String
    Dim rs As Recordset
    Dim i As Byte
    
    Set rs = CurrentDb.OpenRecordset("TableName")
    
    Open strFile For Input As #1
    Do Until EOF(1)
        i = i + 1
        Line Input #1, strLine
        
        If i = 1 Then
            rs.AddNew
            rs!Student_NM = strLine
        ElseIf i = 2 Then
            rs!Student_Major = Mid(strLine, 7)
        ElseIf i = 3 Then
            rs!Student_Class = Mid(strLine, 7)
        End If
        
        If i = 4 Or EOF(1) Then
            rs.Update
            i = 0
        End If
    Loop
    Close #1
    rs.Close
    Set rs = Nothing
    
End Sub

Open in new window

Ron
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spaced45Author Commented:
Worked perfectly. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.