AnthonyJ20
Programmer
Hello. I'm trying to use the script below to import a tab delimited text file to a table I have but I'm having a problem. The data appears garbled in the fields. Here is my script. I commented out all of the rs.field lines except for the first one. Below the script is an example of what the file I'm trying to import looks like. Can anyone tell what I'm doing wrong?
Import Script
Private Sub cmdReadit_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "DeletImport", acViewNormal
DoCmd.Close acQuery, "DeletImport"
Dim filnam As String, s As String, MyLine As String, MyLocation As Long, ch As String
Dim rs As DAO.Recordset, once As Boolean
filnam = "C:\ACCESS\JUNQUE\lbchrupld.txt"
Set rs = CurrentDb.OpenRecordset("lbchrupld")
once = False
If Not IsNull(Me.Text2) Then filnam = Me.Text2
Open filnam For Binary As #1
MyLine = ""
MyLocation = 0
Do While MyLocation < LOF(1)
ch = Input(99, #1)
If once Then
rs.AddNew
rs.Fields(1) = Mid(MyLine, 1, 1)
'rs.Fields(2) = Mid(MyLine, 3, 3)
'rs.Fields(3) = Mid(MyLine, 6, 2)
'rs.Fields(4) = Mid(MyLine, 8, 13)
'rs.Fields(5) = Mid(MyLine, 21, 5)
'rs.Fields(6) = Mid(MyLine, 26, 15)
'rs.Fields(7) = Mid(MyLine, 48, 6)
'rs.Fields(7) = "" & Mid(MyLine, 48, 2) & "/" & Mid(MyLine, 50, 2) & "/" & Mid(MyLine, 52, 2) & ""
'rs.Fields(8) = Mid(MyLine, 55, 5)
'rs.Fields(9) = Mid(MyLine, 62, 4)
'rs.Fields(10) = Mid(MyLine, 66, 5)
'rs.Fields(11) = Mid(MyLine, 90, 8)
rs.Update
End If
once = True
MyLine = ""
MyLine = MyLine & ch
MyLocation = Loc(1)
Loop
MsgBox " File has been successfully imported! "
Close #1 ' Close file.
rs.Close
Set rs = Nothing
DoCmd.OpenForm "frmlbchrupldNew", acNormal
End Sub
Text File
"CH" 1 "FUMC" "" 08/23/2005 813 813 221 221 101 72 0 0 0 0 8 0 11 0 0 0 0 0 0 1734164.16
"CH" 3 "World Com" "" 08/23/2005 190 190 31 31 12 13 206 3 0 0 7 7 96 0 0 0 0 0 0 34514.00
Import Script
Private Sub cmdReadit_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "DeletImport", acViewNormal
DoCmd.Close acQuery, "DeletImport"
Dim filnam As String, s As String, MyLine As String, MyLocation As Long, ch As String
Dim rs As DAO.Recordset, once As Boolean
filnam = "C:\ACCESS\JUNQUE\lbchrupld.txt"
Set rs = CurrentDb.OpenRecordset("lbchrupld")
once = False
If Not IsNull(Me.Text2) Then filnam = Me.Text2
Open filnam For Binary As #1
MyLine = ""
MyLocation = 0
Do While MyLocation < LOF(1)
ch = Input(99, #1)
If once Then
rs.AddNew
rs.Fields(1) = Mid(MyLine, 1, 1)
'rs.Fields(2) = Mid(MyLine, 3, 3)
'rs.Fields(3) = Mid(MyLine, 6, 2)
'rs.Fields(4) = Mid(MyLine, 8, 13)
'rs.Fields(5) = Mid(MyLine, 21, 5)
'rs.Fields(6) = Mid(MyLine, 26, 15)
'rs.Fields(7) = Mid(MyLine, 48, 6)
'rs.Fields(7) = "" & Mid(MyLine, 48, 2) & "/" & Mid(MyLine, 50, 2) & "/" & Mid(MyLine, 52, 2) & ""
'rs.Fields(8) = Mid(MyLine, 55, 5)
'rs.Fields(9) = Mid(MyLine, 62, 4)
'rs.Fields(10) = Mid(MyLine, 66, 5)
'rs.Fields(11) = Mid(MyLine, 90, 8)
rs.Update
End If
once = True
MyLine = ""
MyLine = MyLine & ch
MyLocation = Loc(1)
Loop
MsgBox " File has been successfully imported! "
Close #1 ' Close file.
rs.Close
Set rs = Nothing
DoCmd.OpenForm "frmlbchrupldNew", acNormal
End Sub
Text File
"CH" 1 "FUMC" "" 08/23/2005 813 813 221 221 101 72 0 0 0 0 8 0 11 0 0 0 0 0 0 1734164.16
"CH" 3 "World Com" "" 08/23/2005 190 190 31 31 12 13 206 3 0 0 7 7 96 0 0 0 0 0 0 34514.00