Problem selecting unique records...follow-up (for

# Thread: Problem selecting unique records...follow-up (for

1. Senior Member
Join Date
Dec 1969
Posts
1,100

## Problem selecting unique records...follow-up (for

2. Senior Member
Join Date
Dec 1969
Posts
733

sorry, but I&#039;m a little pressed for time at the moment. However, array numbering starts at zero, so I think<BR><BR>choice = Int( maxrow+1-r * Rnd() ) <BR><BR>has the potential to select a value that is equal to maxrow, but maxrow will be one greater than the highest array element.<BR><BR>Try changing to this<BR><BR>choice = Int( maxrow-r * Rnd() )

3. Senior Member
Join Date
Dec 1969
Posts
1,100

## RE: I get the same error: Subscript out of range

4. Senior Member
Join Date
Dec 1969
Posts
733

## RE: I get the same error: Subscript out of range

Just realised the array is populated using getrows() therefore it will be 2 dimensional. Try using ids(0, choice) instead of ids(choice)

5. Senior Member
Join Date
Dec 1969
Posts
1,100

## RE: I get these errors:

------<BR>Subscript out of range: &#039;ids&#039;<BR>------<BR><BR>When I am using "choice = Int( maxrow-r * Rnd() )" and "ids(0,choice)"<BR><BR>And:<BR>----------<BR>Subscript out of range: &#039;choice&#039;<BR>----------<BR><BR>When I am using "choice = Int( maxrow+1-r * Rnd() )" and ids(0,choice)"<BR>

6. Senior Member
Join Date
Dec 1969
Posts
733

## Which lines?

I assume you have tried the following code:<BR><BR>For r = 0 To 3 <BR> choice = Int( maxrow-r * Rnd() ) <BR> randids(r) = ids(0, choice) <BR> ids(0, choice) = ids( maxrow-r ) <BR>Next <BR><BR>if the error is on the last line in the loop, then it could be ids(maxrow-r) that is giving the error for the same reason as before. So you could try replacing it with ids(maxrow-1-r)

7. Senior Member
Join Date
Dec 1969
Posts
1,100

## RE: These lines...

This is the code:<BR>--------<BR>For r = 0 To 3 <BR>choice = Int( maxrow-r * Rnd() ) &#039;&#039; the line you gave<BR>&#039;choice = Int( maxrow+1-r * Rnd() ) &#039;&#039;the original line from Bill<BR> <BR>randIDs(r) = ids(0,choice) <BR>ids(0,choice) = ids( maxrow-1-r ) &#039; I replaced with what you gave me<BR>Next <BR>---------<BR><BR>But I still get Subscript out of range!<BR>

8. Senior Member
Join Date
Dec 1969
Posts
733

## RE: These lines...

Doh! I missed the 2 dimensions again! Try this:<BR>ids(0, choice) = ids(0, maxrow-1-r)

9. Senior Member
Join Date
Dec 1969
Posts
1,100

## RE: OK, it works...now the second part :)

10. Senior Member
Join Date
Dec 1969
Posts
1,100

## RE: Ops! Sometimes...

It works...sometimes not!<BR><BR>This is the line: ids(0,choice) = ids(0, maxrow-1-r ) <BR><BR>Sometimes it works as it is now...sometimes I get this error: Subscript out of range: &#039;[number: -1]&#039;<BR><BR>If I am changing ids(0, maxrow-1-r ) with ids(0, maxrow-r ) then it works, sometimes, when I click Refesh...other times it give me this error: Subscript out of range: &#039;choice&#039;<BR><BR>There are records because I am checking if rs.eof (before using GetRows).<BR><BR>What could it be this time?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•