ThunderGeek
Technical User
Greetings,
I am trying to create a loop that fills a table ([orders detailkpi]) from a text file(C:\shopsite\ORDERS\1OrderDetails.txt).
The loop section isn’t working very well. I keep getting a runtime error 3421. I probably have wrote something incorrectly and can not see the forest for the trees. Any help would be most appreciated. TG
Function FillOrderInfoTA()
Set Connection = Application.CurrentProject.Connection
Set db = CurrentDb
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
Set rs = db.OpenRecordset("Order DetailsKPI")
Dim reccount As Long
Dim x As Integer
Open "C:\shopsite\ORDERS\1OrderDetails.txt" For Input As #1
Do While Not EOF(1)
'read in the first line up to the crlf
Line Input #1, record
reccount = reccount + 1
If reccount = 1 Then GoTo SkipHeader
'use split function and tab as delim.
ParsedRecord = Split(record, Chr(9))
'--- set the fields inside the loop -
rs.AddNew
rs![WebID2] = ParsedRecord(0)
rs![Order ID] = ParsedRecord(1)
rs![Product ID] = ParsedRecord(3)
rs![SALE PRICE] = ParsedRecord(4)
rs![Qty] = ParsedRecord(5)
rs.Update
'5 is the ubound for one order
If UBound(ParsedRecord) > 5 Then
'add another record for each additional order detail provided
For x = 6 To UBound(ParsedRecord) Step 4
rs.AddNew
rs![WebID2] = ParsedRecord(0)
rs![Order ID] = ParsedRecord(x + 1)
rs![Product ID] = ParsedRecord(x + 2)
rs![SALE PRICE] = ParsedRecord(x + 3)
rs![Qty] = ParsedRecord(x + 4)
rs.Update
Next x
End If
SkipHeader:
Loop
Close #1
rs.Close
Set rs = Nothing
End Function
I am trying to create a loop that fills a table ([orders detailkpi]) from a text file(C:\shopsite\ORDERS\1OrderDetails.txt).
The loop section isn’t working very well. I keep getting a runtime error 3421. I probably have wrote something incorrectly and can not see the forest for the trees. Any help would be most appreciated. TG
Function FillOrderInfoTA()
Set Connection = Application.CurrentProject.Connection
Set db = CurrentDb
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
Set rs = db.OpenRecordset("Order DetailsKPI")
Dim reccount As Long
Dim x As Integer
Open "C:\shopsite\ORDERS\1OrderDetails.txt" For Input As #1
Do While Not EOF(1)
'read in the first line up to the crlf
Line Input #1, record
reccount = reccount + 1
If reccount = 1 Then GoTo SkipHeader
'use split function and tab as delim.
ParsedRecord = Split(record, Chr(9))
'--- set the fields inside the loop -
rs.AddNew
rs![WebID2] = ParsedRecord(0)
rs![Order ID] = ParsedRecord(1)
rs![Product ID] = ParsedRecord(3)
rs![SALE PRICE] = ParsedRecord(4)
rs![Qty] = ParsedRecord(5)
rs.Update
'5 is the ubound for one order
If UBound(ParsedRecord) > 5 Then
'add another record for each additional order detail provided
For x = 6 To UBound(ParsedRecord) Step 4
rs.AddNew
rs![WebID2] = ParsedRecord(0)
rs![Order ID] = ParsedRecord(x + 1)
rs![Product ID] = ParsedRecord(x + 2)
rs![SALE PRICE] = ParsedRecord(x + 3)
rs![Qty] = ParsedRecord(x + 4)
rs.Update
Next x
End If
SkipHeader:
Loop
Close #1
rs.Close
Set rs = Nothing
End Function