getrows in VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello i'm trying to read data from a table in a loop and put it in a long
string so i have code that looks like this

data() = Records.GetRows(Records.Properties.Count)

For i = 0 To Records.RecordCount


outputString = outputString + "|"
outputString = outputString + CStr(data(0, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(1, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(2, i))

Next

This all looks good to me however there are two problems

1) it only reads the first 5 records ignoring the 6th record

2) uppon reaching data(2,4) it contains Null and i get an illegal use of
Null error

am i doing someting wrong?? thanks!!
 
You can't concatenate a null onto a string.
Also bear in mind that a string has a maximum length
Why are you trying to do this, its somewhat bizarre?

Dorian
 
dave said:
Hello i'm trying to read data from a table in a loop and put it in a long
string so i have code that looks like this

data() = Records.GetRows(Records.Properties.Count)

For i = 0 To Records.RecordCount

outputString = outputString + "|"
outputString = outputString + CStr(data(0, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(1, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(2, i))

Next

This all looks good to me however there are two problems

1) it only reads the first 5 records ignoring the 6th record

2) uppon reaching data(2,4) it contains Null and i get an illegal use of
Null error


A rather strange thing to do, but the big problem with your
code is that Null propagates across the + operator. You
should use the & operator instead.

The actual error you got was because CStr() does not allow
for a Null value. The Str() function does allow for Null,
but it also adds a space character in front of positive
numbers and it does not accept strings. You may prefer to
use CStr(Nz(data(x,i),"")

OTOH, Access will cast the data value automaticallym so you
can get away with just using:

outputString = outputString & data(2, i)
 
Thanks for all these answers i guess i wasn't clear about what was going on
becasue the thing that confuses me about the null error is that the data
shouldn't be null. data(2,i) should contain a string but when GetRows
retrieves the data from the table it makes it null at data(2,4) and ignores
the next row of data in the table. though thanks for the tip on using &
instead of + i will look further into that.
 
I am not a fan of GetRows and would prefer to work directly
with the recordset. Perhaps someone that knows more about
it than me could help if you posted a new thread that
focused on the GetRows question.
 
dave said:
Hello i'm trying to read data from a table in a loop and put it in a
long string so i have code that looks like this

data() = Records.GetRows(Records.Properties.Count)

For i = 0 To Records.RecordCount


outputString = outputString + "|"
outputString = outputString + CStr(data(0, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(1, i))
outputString = outputString + "|"
outputString = outputString + CStr(data(2, i))

Next

This all looks good to me however there are two problems

1) it only reads the first 5 records ignoring the 6th record

2) uppon reaching data(2,4) it contains Null and i get an illegal use
of Null error

am i doing someting wrong?? thanks!!

Is Records a Recordset object? What are you trying to specify by
"Records.Properties.Count"? Shouldn't that just be

data = Records.GetRows(Records.RecordCount)

?
Note that, depending on the circumstances, you may have to first move to
the end of the recordset and make the RecordCount property have an
accurate value.

Then later, your loop
For i = 0 To Records.RecordCount

should be

For i = 0 To (Records.RecordCount - 1)
 
Why do you use Records.Properties.Count in one place, but
Records.RecordCount in t'other?

And if the latter value is the # of records in the recordset, you'd
need the loop to go from zeo to that value /minus one/. IOW you have an
"off by one" error.

HTH,
TC
 
Back
Top