J
James Gaylord via AccessMonster.com
I have a large file that I import on a weekly basis. Currently it is almost
196,000 records and grows each week. I am running through the following code
and I noticed afdter about 70,000 records it starts slowing way down. I
believe it is because I am reading in 1 line at a time and once it reaches
this point it is haiving to go back out to the hard drive and read additional
data. Is there a way and does it make sense to read the entire file in
before I start parsing the records.
I thought I had seen somehting in another post about reading in the entire
file first and then doing the parsing, but I can't locate this anywhere now.
TIA
Dim iFile As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim nLine, st2nd, st3rd, stUOM, stDesc1, stDesc2 As String
Dim lngItem As Long
Dim tStart As Single
Dim x As Long
' Deletes the current table before running the update
On Error GoTo comUpdate_Click_Error
tStart = Timer
DoCmd.OpenQuery "qryelJDEItems", acViewNormal, acEdit
Set db = CurrentDb()
Set rs = db.OpenRecordset("JDEItemNumbers")
iFile = FreeFile
Open "Z:\VMITMMST.csv" For Input Access Read As iFile
x = 1
Do Until EOF(iFile)
Me.lblRecCount.Caption = x & " records processed"
Me.Repaint
Line Input #iFile, nLine
st2nd = Split(nLine, ",")(0)
If Left(st2nd, 1) = """" Then
st2nd = Mid(st2nd, 2, Len(st2nd) - 2)
End If
st3rd = Split(nLine, ",")(1)
If Left(st3rd, 1) = """" Then
st3rd = Mid(st3rd, 2, Len(st3rd) - 2)
End If
lngItem = Split(nLine, ",")(2)
stUOM = Split(nLine, ",")(3)
If Left(stUOM, 1) = """" Then
stUOM = Mid(stUOM, 2, Len(stUOM) - 2)
End If
stDesc1 = Split(nLine, ",")(4)
If Left(stDesc1, 1) = """" Then
stDesc1 = Mid(stDesc1, 2, Len(stDesc1) - 2)
End If
stDesc2 = Split(nLine, ",")(5)
If Len(stDesc2) > 2 And Left(stDesc2, 1) = """" Then
stDesc2 = Mid(stDesc2, 2, Len(stDesc2) - 2)
Else
stDesc2 = ""
End If
rs.AddNew
rs![2NDItemNumber] = st2nd
rs![3RDIteNumber] = st3rd
rs![ItemNumber(Short)] = lngItem
rs!UOM = stUOM
rs!Desc1 = stDesc1
rs!Desc2 = stDesc2
rs.Update
x = x + 1
Loop
rs.Close
db.Close
Close iFile
--
James B Gaylord
From the Wolf Comes the Strength of the Pack
From the Pack Comes the Strength of the Wolf
- R Kipling
Message posted via AccessMonster.com
196,000 records and grows each week. I am running through the following code
and I noticed afdter about 70,000 records it starts slowing way down. I
believe it is because I am reading in 1 line at a time and once it reaches
this point it is haiving to go back out to the hard drive and read additional
data. Is there a way and does it make sense to read the entire file in
before I start parsing the records.
I thought I had seen somehting in another post about reading in the entire
file first and then doing the parsing, but I can't locate this anywhere now.
TIA
Dim iFile As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim nLine, st2nd, st3rd, stUOM, stDesc1, stDesc2 As String
Dim lngItem As Long
Dim tStart As Single
Dim x As Long
' Deletes the current table before running the update
On Error GoTo comUpdate_Click_Error
tStart = Timer
DoCmd.OpenQuery "qryelJDEItems", acViewNormal, acEdit
Set db = CurrentDb()
Set rs = db.OpenRecordset("JDEItemNumbers")
iFile = FreeFile
Open "Z:\VMITMMST.csv" For Input Access Read As iFile
x = 1
Do Until EOF(iFile)
Me.lblRecCount.Caption = x & " records processed"
Me.Repaint
Line Input #iFile, nLine
st2nd = Split(nLine, ",")(0)
If Left(st2nd, 1) = """" Then
st2nd = Mid(st2nd, 2, Len(st2nd) - 2)
End If
st3rd = Split(nLine, ",")(1)
If Left(st3rd, 1) = """" Then
st3rd = Mid(st3rd, 2, Len(st3rd) - 2)
End If
lngItem = Split(nLine, ",")(2)
stUOM = Split(nLine, ",")(3)
If Left(stUOM, 1) = """" Then
stUOM = Mid(stUOM, 2, Len(stUOM) - 2)
End If
stDesc1 = Split(nLine, ",")(4)
If Left(stDesc1, 1) = """" Then
stDesc1 = Mid(stDesc1, 2, Len(stDesc1) - 2)
End If
stDesc2 = Split(nLine, ",")(5)
If Len(stDesc2) > 2 And Left(stDesc2, 1) = """" Then
stDesc2 = Mid(stDesc2, 2, Len(stDesc2) - 2)
Else
stDesc2 = ""
End If
rs.AddNew
rs![2NDItemNumber] = st2nd
rs![3RDIteNumber] = st3rd
rs![ItemNumber(Short)] = lngItem
rs!UOM = stUOM
rs!Desc1 = stDesc1
rs!Desc2 = stDesc2
rs.Update
x = x + 1
Loop
rs.Close
db.Close
Close iFile
--
James B Gaylord
From the Wolf Comes the Strength of the Pack
From the Pack Comes the Strength of the Wolf
- R Kipling
Message posted via AccessMonster.com