By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,829 Members | 673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,829 IT Pros & Developers. It's quick & easy.

string is interperted literally

P: n/a
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 & "] & "
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,
StrText is interperted as string

rs.MoveNext
Loop
rs.Close
End If

Thanks in advance for the help.
Jan 4 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jan 3, 11:29*pm, pmacdid...@gmail.com wrote:
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 & "] & "
* * * 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,
StrText is interperted as string

* * * * * * rs.MoveNext
* * * * * * Loop
* * * * * * rs.Close
* * * * End If

Thanks in advance for the help.
Maybe:

varFieldValue = rs(rs.Fields(i).Name)

Note: varFieldValue can be Null.

James A. Fortune
CD********@FortuneJames.com
Jan 4 '08 #2

P: n/a
On Jan 4, 12:07*am, CDMAPos...@fortunejames.com wrote:
On Jan 3, 11:29*pm, pmacdid...@gmail.com wrote:


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 & "] & "
* * * 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,
StrText is interperted as string
* * * * * * rs.MoveNext
* * * * * * Loop
* * * * * * rs.Close
* * * * End If
Thanks in advance for the help.

Maybe:

varFieldValue = rs(rs.Fields(i).Name)

Note: varFieldValue can be Null.

James A. Fortune
CDMAPos...@FortuneJames.com- Hide quoted text -

- Show quoted text -
unfortunately that does not work either. I am able to get the value
initially, so I can get the value inside the for loop, but in the do
while loop, the variables are treated as text, so i get the same thing
all the way through the record set.
Jan 4 '08 #3

P: n/a
pm********@gmail.com wrote in news:a36e8558-ba97-4468-8825-77cb3a335bb8
@r60g2000hsc.googlegroups.com:
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.
It has snowed here a lot recently. I have been clearing my driveway with a
screw-driver. There have been problems. So I wrote into Comp-
Driveways/OldMan-Clear and asked for help with [clearing my driveway with a
screw-driver]. Some kind soul there suggested that almost never does one
NEED to clear his/her driveway with a screw-driver and that possibly I
should ask for suggestion on how to [clear my driveway].
When I did that, someone suggested that I use a shovel. Now I canít
remember what the problem with the screw-driver was.
PS My driveway is clear.
Jan 4 '08 #4

P: n/a
pm********@gmail.com wrote:
On Jan 4, 12:07 am, CDMAPos...@fortunejames.com wrote:
>>On Jan 3, 11:29 pm, pmacdid...@gmail.com wrote:

>>>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 & "] & "
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,
StrText is interperted as string
>> rs.MoveNext
Loop
rs.Close
End If
>>>Thanks in advance for the help.

Maybe:

varFieldValue = rs(rs.Fields(i).Name)

Note: varFieldValue can be Null.

James A. Fortune
CDMAPos...@FortuneJames.com- Hide quoted text -

- Show quoted text -


unfortunately that does not work either. I am able to get the value
initially, so I can get the value inside the for loop, but in the do
while loop, the variables are treated as text, so i get the same thing
all the way through the record set.
Wouldn't your value of strText be something like
"rs![Field1] & rs![Field2] & rs![Field3] & rs![Field4] & "...
when you get to 1?

You put a
Debug.Print StrText
in your code. Whats the output? Something like
rs![Field1] &
rs![Field1] & rs![Field2] &
rs![Field1] & rs![Field2] & rs![Field3] &
rs![Field1] & rs![Field2] & rs![Field3] & rs![Field4] &
?

You mention "StrText is interperted as string". Most of us would think
that strText is a string. What do you think it should be?

Flowers
http://www.youtube.com/watch?v=hMGpGZvr-G0
Jan 4 '08 #5

P: n/a
pm********@gmail.com wrote:
>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.
Why don't you know the field names?

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Jan 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.