Excel cells are empty when I download as400 data using excel

DavidCorrez

New Member
Joined
Sep 11, 2002
Messages
7
I am using vba in excel to download data directly from as400. The code is:

Sub ImportFromAS400()

Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
Set TargetRange = TargetRange.Cells(1, 1)
' open the database
Set cn = New ADODB.Connection

cn.Open "Provider=IBMDA400;Data source=TEAUST;User Id=;Password=;");

Set rs = New ADODB.Recordset
With rs
.Open "SELECT BPCSUS.ID,BPCSUS.SEQ, BPCSUS.IPROD, BPCSUS.IDESC FROM TEAUST.BPCSUS.MBM", cn, , , adCmdText

For intColIndex = 0 To rs.Fields.Count - 1

TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name

Next


TargetRange.Offset(1, 0).CopyFromRecordset rs

End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub


The problem is that when the cells are downloaded to excel, some cells are left blank. The fields are empty
(When I run msquery or do a link to access the values for the fields are there. I know the sql is correct in my vba code (because i took it of the msquery)).
It retrieves all the available records for some fields only. The field that are empty when exported to excel are BPCSUS.SEQ abd BPCSUS.IDESC.

Does anyone know why?

Cheers DC
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Watch MrExcel Video

Forum statistics

Threads
1,122,658
Messages
5,597,403
Members
414,142
Latest member
Banyangt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top