|
-
Nov 7th, 2001, 04:13 PM
#1
Thread Starter
Fanatic Member
random...
Guys/Gals
Any idea as to how to randomly select 10 records from a table
of users? using sql
-
Nov 7th, 2001, 04:33 PM
#2
-= B u g S l a y e r =-
not sure if I can give u an answer using SQL only... is opening a recset and pick them from there ok?
-
Nov 7th, 2001, 04:34 PM
#3
Thread Starter
Fanatic Member
..
Would be fine... but How to randomize.. it
-
Nov 8th, 2001, 01:21 AM
#4
-= B u g S l a y e r =-
I'll post a sample for u in a couple of hours... sorry about the delay.
-
Nov 8th, 2001, 04:04 AM
#5
-= B u g S l a y e r =-
hmm..funny stuff 
VB Code:
Private Sub Command1_Click()
Dim db As Database
Dim rs As Recordset
Dim iNumOfUsersToPick
Dim iUsed() As Integer
Dim bUsed As Boolean
Dim iNextUser As Integer
Dim i As Integer
Dim x As Integer
Dim sUserList As String
Dim iSelMax As Integer
Randomize Timer
iNumOfUsersToPick = 10
ReDim iUsed(iNumOfUsersToPick)
Set db = OpenDatabase("D:\TEST.MDB")
Set rs = db.OpenRecordset("Users")
rs.MoveLast
rs.MoveFirst
iSelMax = rs.RecordCount
For i = 0 To iNumOfUsersToPick
bUsed = True
While bUsed
bUsed = False
iNextUser = Int(iSelMax * Rnd)
For x = 0 To iNumOfUsersToPick
If iNextUser = iUsed(x) Then
bUsed = True
Exit For
End If
Next x
Wend
iUsed(i) = iNextUser
rs.MoveFirst
rs.Move iNextUser
sUserList = sUserList & rs("Name") & vbCrLf
Next i
MsgBox sUserList
End Sub
-
Nov 8th, 2001, 04:06 AM
#6
-= B u g S l a y e r =-
Database : D:\TEST.MDB
Table: Users
Field: Name
if u have any questions regarding the above sample, just ask
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|