• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

updating an access database table from a textfile

i'm trying to write a function that will open a text file for reading, then read the file line by line and put it into an existing table- graph. i am trying first just to read the lines and past it into one of the table's fields without deviding it to fields.
i wrote:
Private Sub load_Click()
Dim dbss As Database
Set dbss = OpenDatabase("db3") 'db3 is my dbase name
Dim textline As String
Open "a:movefile.txt" For Input As #1
Do While Not EOF(1)
    Line Input #1, textline
    dbss.TableDefs("graph").Fields("num") = textline
Close #1
End Sub
the thing is it doesn't work.
the textline format in the file is:
:spo2= (3 digits number) pr= (3 digits number) no probe
if you can please tell me also how to read the file so i can imidiatly past the 3 digits numbers in to diffrent fields in table graph i would give you a very high score.
thank you my saviour.
1 Solution
I think I see what you are trying to do. The code looks roughly like this:

Private Sub foo()

Dim db As Database
Dim rs As Recordset
Dim h As Long
Dim s As String
Dim n1 As String
Dim n2 As String
Dim i As Integer

    Set db = OpenDatabase("db3")
    Set rs = db.OpenRecordset("graph", dbOpenTable)
    h = FreeFile
    Open "a:movefile.txt" For Input As #h
    Do While Not EOF(h)
        Line Input #h, s
        i = InStr(s, "spo2=")
        n1 = Mid$(s, i + 5, 3)
        i = InStr(s, "pr=")
        n2 = Mid$(s, i + 3, 3)
        rs.Fields("num1").Value = n1
        rs.Fields("num2").Value = n2
    Close #h
    Set rs = Nothing
    Set db = Nothing

End Sub

Obviously you will need to change the field names to suit. Also, some error handling and a transaction wouldn't go amiss.
ilanmAuthor Commented:
i don't know if it works but this is the first time someone actualy submits a code to his answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now