loop through field names, then use to loop through records topopulate grid

P

pmacdiddie

Sorry, I know this has been done 1000 times. The problem is i need
to
loop though a recordset and I dont know the field names, so they have
to be looked up. When i pass them to get the values, it passes as a
literal.

fcount = rs.Fields.Count
'Debug.Print fcount
For i = 0 To fcount - 1


StrText = StrText & "rs![" & rs.Fields(i).Name & "] & " ++++++
THIS PART WORKS
Debug.Print StrText


ctGrid0.AddColumn rs.Fields(i).Name, rs.Fields(i).Size
ctGrid0.ColumnSortable(i) = -1


If fcount - i = 1 Then
Do While Not rs.EOF


ncount = ctGrid0.AddItem(StrText) ****** Problem is here,
HERE IT IS LITERAL
StrText is interperted as string


rs.MoveNext
Loop
rs.Close
End If


Thanks in advance for the help.
 
D

Douglas J. Steele

Try:

fcount = rs.Fields.Count
'Debug.Print fcount
For i = 0 To fcount - 1
ctGrid0.AddColumn rs.Fields(i).Name, rs.Fields(i).Size
ctGrid0.ColumnSortable(i) = -1
Next i
Do While Not rs.EOF
For i = 0 To fcount - 1
StrText = StrText & rs.Fields(i) & ";" &

Next i
ncount = ctGrid0.AddItem StrText
rs.MoveNext
Loop
rs.Close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top