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
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