
Originally Posted by
ermagarden
Is it true that the import has to be done row by row....so read the excel file row by row and then insert into AS400 table row by row??
No, this is not true. The iSeries Access OLEDB provider allows you to retrieve data from the i5 as an ADODB.recordset.
This code utilizes the OLE DB provider that comes with iSeries Access for Windows. If you don't supply user id and password, you will be prompted for them when the "objConn.Open" statement is executed.
Code:
Set objConn = New ADODB.Connection
objConn.Open "Provider=IBMDA400;" & _
"Data Source={your IP address};"
Set objRS = New ADODB.Recordset
With objRS
.ActiveConnection = objConn
.Source = "SELECT ITM05 FROM MYLIB.ITEMSTEP"
.Open
lngOffset = 0
If Not .EOF Then
'add field headers
For Each objFields In .Fields
Sheets2.Offset(0, lngOffset).Value = objFields.Name
lngOffset = lngOffset + 1
Next objFields
Sheet2.Resize(1, .Fields.Count).Font.Bold = True
'dump the recordset to the spreadsheet
Sheet2.Offset(1, 0).CopyFromRecordset objRS
Sheet2.UsedRange.EntireColumn.AutoFit
Else
MsgBox "Error: no records returned.", vbCritical
End If
.Close
End With
Or, if you like, you can read through the recordset one record at a time.
Bookmarks