Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
trying to use select query in excel macros. rs.fields.count returns the count of columns in the select query. Actually i need the count of rows in the table.

also recordcount value is -1. however when the same query is excuted in db2, it works fine.

Eg:
VB
sql = "select a,b,c from tblname where d = 100;"

Set cmdobj = New ADODB.Command

cmdobj.ActiveConnection = varcnn
cmdobj.CommandText = sql

Set rs = cmdobj.Execute(sql)

For i = 0 To rs.Fields.Count - 1
   Sheet2.Cells(r, i + 1) = rs.Fields(i).Value
   Sheet2.Cells(r, i + 1).Interior.ColorIndex = 36
   Sheet2.Cells(r, i + 1).Borders.Value = 1
Next i

thanks in advance
Posted
Updated 13-May-14 12:22pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900