Partial Importing From External Text File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I have a project requiring me to regularly import the following items
into a Factor Table. From the IMPORT button I'm needing to set code to bring
in the following data from the "C:\Scores.txt" file but I need to leave out
the bracketed items while importing the data underneath. Please note that
the factors have 4 separate entries on one line where each 2-digit entry has
its own Factor 1 field Factor 2 field, etc.

Any help will be tremendously appreciated.

[ROID]
200405250001IN

[SSN]
444-33-8888

[QTY]
502

[FACTORS]
02,22,29,44

[DATE]
11/15/2004
 
What's the structure of the Factor Table you're trying to import this into? Assumeing that all of the fields in brackets you describe are fields in the table, it would look like:

Dim fh As Integer
Dim RecordCount as Integer
Dim sRec As String
Dim sField As String
Dim RS As Recordset

Set RS = CurrentDb.OpenRecordset("Table", dbOpenTable, dbAppendOnly, dbOptimistic)

RecordCount = 0
fh = FreeFile
Open "C:\Scores.txt" For Input Access Read Shared As #fh

Do Until EOF(fh)
Line Input #fh, sRec
If sRec = "ROID" Then
If RecordCount > 0 Then
RS.Update
End If
RecordCount = RecordCount + 1
RS.AddNew
End If
If Left$(sRec, 1) = "[" Then
sField = Mid$(sRec, 2, len(line)-2)
Line Input #fh, sRec
If Not EOF(fh)
RS.Fields(sField).Value = sRec
End If
End If
Loop

Close #fh

If RecordCount > 0 Then
RS.Update
End If

RS.Close
Set RS = Nothing

*****************************************
* A copy of the whole thread can be found at:
* http://www.accessmonster.com/Uwe/Forum.aspx/access-externaldata/7129
*
* Report spam or abuse by clicking the following URL:
* http://www.accessmonster.com/Uwe/Abuse.aspx?aid=08e5913a9ade4f70978d84655362e734
*****************************************
 
Back
Top