Recordcount / Variable

G

Guest

Hi there.
At this point i am SOOO confused.
I have a problem. Indeed.

A variable I am using to ReDim an Array is not getting the number I need. I
get a "subscript" error because I am trying to store an element in the array,
but the array has been limited to the wrong amount of elements allowed.

heres the code:
intRecords = rsMyRS.recordCount
ReDim strArray(intRecords)

heres the results:

variable
http://img47.imageshack.us/img47/4316/recordcount1sk.jpg

recordcount
http://img129.imageshack.us/img129/6287/recordcount23ja.jpg


the variable is stored as an integer. I tried Long, string, variant, double.
Same result everytime. Subscript out of range - trying to access an element
of the array that doesnt exist (trying to store a string in strArray(3)
...when stArray has been redim'd to max strArray(2) )

Not sure what to do.
Thanks.
-State
 
R

RoyVidar

State Troopers wrote in message
Hi there.
At this point i am SOOO confused.
I have a problem. Indeed.

A variable I am using to ReDim an Array is not getting the number I
need. I get a "subscript" error because I am trying to store an
element in the array, but the array has been limited to the wrong
amount of elements allowed.

heres the code:
intRecords = rsMyRS.recordCount
ReDim strArray(intRecords)

heres the results:

variable
http://img47.imageshack.us/img47/4316/recordcount1sk.jpg

recordcount
http://img129.imageshack.us/img129/6287/recordcount23ja.jpg


the variable is stored as an integer. I tried Long, string, variant,
double. Same result everytime. Subscript out of range - trying to
access an element of the array that doesnt exist (trying to store a
string in strArray(3) ..when stArray has been redim'd to max
strArray(2) )

Not sure what to do.
Thanks.
-State

Without seing a bit of code, I think it's somewhat hard to guess ...

Some general comments

If you're using DAO, rememeber that the recordcount property will show
the number of accessed records. To be sure to have the correct count,
issue for instance a .movelast prior to fetching the recordcount.

If you're using ADO, then my view is that the ADO recordcount is not
reliable. Some says it's OK if you just specify the correct cursor
location and cursor type, though ... I still say that to get a correct
and reliable recordcount in ADO, use a select count(*) on the recordset
in stead.
 
R

RoyVidar

RoyVidar wrote in message <[email protected]> :
Sorry, the last part should read:
I still say that to get a correct and reliable recordcount in ADO, use
a
select count(*) on the *table* or *query* in stead.
 
M

Michel Walsh

Hi,


That is a second good reason to use SQL rather than a recordset. Note that
the SQL statement is not that complex, as already supplied, it is a simple
SELECT COUNT(*) FROM tableName.


Vanderghast, Access MVP
 

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