Nth select

i was thinking random was what you were after and i would have thought it more statistically valid but i'm not a statistician either. v.khawaja's post above will pick you every 5th record out rather than a random selection. The code i wrote could select the first 200 records and no others, that's the way it goes. If you need any help getting
v.khawaja 's code to work post again

HTH

Drew
 
A Huge Thank You to all for reaching out and assisting. I now have 2 codes which select either 1. Randomly 2. Sequentially

This is awesome, makes my day

Special thanks to Drew for staying with me on this...

Best Regards,

Manu
 
pleasure, it's nice to write some code to do something i've not done before, especialy when it does something useful for someone.
And a special thanks from me to The_Doc _Man, without whom we'd now be knee deep in queries and functions, thanks mate

Drew

[This message has been edited by Drew (edited 08-24-2001).]
 
Getting errors with Access2000

Both codes [outlined in the attached message string] have worked very well for me as long as I was using Access97, however, I recently upgraded to Access 2000 and they don't seem to work anymore.

Can someone help identify and correct the problem?

All help is much appreciated.

Regards,

Manu

Attached is a screenshot of what I'm getting when using either of the codes in Access 2000
 
Here are the 2 codes

Sub Runthething()
changeYN 96
End Sub
Sub changeYN(bytpercSel As Byte)
Dim rst As Recordset
Dim dbs As Database
Dim x As Integer
Dim lngTotalRecords As Long
Dim lngNumToSet As Long
Set dbs = CurrentDb
dbs.Execute "UPDATE CEON_AGE SET chosen=False"
Set rst = dbs.OpenRecordset("CEON_AGE", dbOpenDynaset)
Randomize
rst.MoveLast
lngTotalRecords = rst.RecordCount
lngNumToSet = (bytpercSel * 0.01 * lngTotalRecords)
Do Until x >= lngNumToSet
With rst
.MoveFirst
.Move Int(lngTotalRecords * Rnd)
If Not .Fields("chosen") Then
.Edit
.Fields("chosen") = True
.Update
x = x + 1
End If
End With

****************************************************

Private Sub cmdWhatEver()
Dim rst As Recordset
Dim dbs As Database
Dim intCounter As Integer
Set dbs = CurrentDb
dbs.Execute "UPDATE CEON_AGE SET chosen=False"
Set rst = dbs.OpenRecordset("CEON_AGE", dbOpenDynaset)
intCounter = 1
rst.MoveFirst
While Not rst.EOF
If intCounter = 20 Then
rst.Edit
rst!chosen = True
rst.Update
intCounter = 1
End If
intCounter = intCounter + 1
rst.MoveNext
Wend
End Sub

****************************************************

Trying to run either of the 2 results in:

1. Compile Error "User-Defined Type not defined

2. Yellow Highlights "Sub changeYN(bytpercSel As Byte)"




All help is appreciated....


Manu
 
Screenshot

Here's the screenshot
 

Attachments

  • error.png
    error.png
    31.2 KB · Views: 121
Getting Syntax Compile Error

Attached is screenshot indicating your suggested syntax, however, it gives a compile error....

Manu
 

Attachments

  • error.png
    error.png
    33.7 KB · Views: 119
1) There is no X= 0 line.... Although this works its "Bad practice"
Dim rst as DAO.Recordset
Dim dbs as DAO.Database
should relieve your troubles

How ever make sure DAO is referenced...... (from a module in the menu Tools=>References)

Regards
 
Just thought i would give you another thought....

rnd give a number >= 0 and < 1

Thus your LAST record will NEVER EVER be selected!!!! Just a mind you.....

Regards
 
Thank You Sir,

Adding the DAO prefix is fine however, I'm not clear as to where in the code should I insert your suggested modifications

rnd give a number >= 0 and < 1

There is no X= 0 line.... Although this works its "Bad practice"

[PS: I did not author this code and neither am I a programmer....& I appreciate you bearing with me on this]

Never being able to select the last record is something that I can live with.

Regards,

Manu
 
just add the respective previxed at the respective dim lines in your code....

Regards
 

Users who are viewing this thread

Back
Top Bottom