Connecting Tech Pros Worldwide Forums | Help | Site Map

string is interperted literally

pmacdiddie@gmail.com
Guest
 
Posts: n/a
#1: Jan 4 '08
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.

CDMAPoster@fortunejames.com
Guest
 
Posts: n/a
#2: Jan 4 '08

re: string is interperted literally


On Jan 3, 11:29*pm, pmacdid...@gmail.com wrote:
Quote:
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
CDMAPoster@FortuneJames.com
pmacdiddie@gmail.com
Guest
 
Posts: n/a
#3: Jan 4 '08

re: string is interperted literally


On Jan 4, 12:07*am, CDMAPos...@fortunejames.com wrote:
Quote:
On Jan 3, 11:29*pm, pmacdid...@gmail.com wrote:
>
>
>
>
>
Quote:
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.
>
Quote:
* fcount = rs.Fields.Count
* * * * 'Debug.Print fcount
* *For i = 0 To fcount - 1
>
Quote:
* * * StrText = StrText & "rs![" & rs.Fields(i).Name & "] & "
* * * Debug.Print StrText
>
Quote:
* * * ctGrid0.AddColumn rs.Fields(i).Name, rs.Fields(i).Size
* * * ctGrid0.ColumnSortable(i) = -1
>
Quote:
* * * If fcount - i = 1 Then
* * * * * * Do While Not rs.EOF
>
Quote:
* * * * * * ncount = ctGrid0.AddItem(StrText) ******* Problem is here,
StrText is interperted as string
>
Quote:
* * * * * * rs.MoveNext
* * * * * * Loop
* * * * * * rs.Close
* * * * End If
>
Quote:
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.
lyle fairfield
Guest
 
Posts: n/a
#4: Jan 4 '08

re: string is interperted literally


pmacdiddie@gmail.com wrote in news:a36e8558-ba97-4468-8825-77cb3a335bb8
@r60g2000hsc.googlegroups.com:
Quote:
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.
Salad
Guest
 
Posts: n/a
#5: Jan 4 '08

re: string is interperted literally


pmacdiddie@gmail.com wrote:
Quote:
On Jan 4, 12:07 am, CDMAPos...@fortunejames.com wrote:
>
Quote:
>>On Jan 3, 11:29 pm, pmacdid...@gmail.com wrote:
>>
>>
>>
>>
>>
>>
Quote:
>>>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.
>>
Quote:
>> fcount = rs.Fields.Count
>> 'Debug.Print fcount
>> For i = 0 To fcount - 1
>>
Quote:
>> StrText = StrText & "rs![" & rs.Fields(i).Name & "] & "
>> Debug.Print StrText
>>
Quote:
>> ctGrid0.AddColumn rs.Fields(i).Name, rs.Fields(i).Size
>> ctGrid0.ColumnSortable(i) = -1
>>
Quote:
>> If fcount - i = 1 Then
>> Do While Not rs.EOF
>>
Quote:
>> ncount = ctGrid0.AddItem(StrText) ****** Problem is here,
>>>StrText is interperted as string
>>
Quote:
>> rs.MoveNext
>> Loop
>> rs.Close
>> End If
>>
Quote:
>>>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
Tony Toews [MVP]
Guest
 
Posts: n/a
#6: Jan 4 '08

re: string is interperted literally


pmacdiddie@gmail.com wrote:
Quote:
>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/
Closed Thread