Random Select from Datasheet

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,
Sorry to repost this but I have not had any luck in finding any results for
this thread.

On my form "frmEmailSelect" I have a subform "frmSubFrmEmails"which lists
Email addresses in datasheet view.
On the main form I have a command button which I would like to click, and a
random email to be selected, (" A Winning Email like a Lottery " )
I would then like this email address to be displayed in a text box
"TxtBoxWin"on the main form.

Please help

Kind Regards

John
 
hi John,
On the main form I have a command button which I would like to click, and a
random email to be selected, (" A Winning Email like a Lottery " )
I would then like this email address to be displayed in a text box
"TxtBoxWin"on the main form.
Use Int(rs.RecordCount * Rnd) to get your random number:

Dim rs As DAO.Recordset
Dim Count As Integer

Set rs = RecordsetClone
rs.MoveLast
rs.MoveFirst

' take look at the help,
' maybe you can use (ADODB.Recordset?)
' rs.MoveBy(Int(rs.RecordCount * Rnd))
For Count = 0 to Int(rs.RecordCount * Rnd)
rs.MoveNext
Next Count



mfG
--> stefan <--
 
Stefan
Than for the reply. However I am having difficulty with this code.
How do I use it?
I need to click the command button and select an email address from the
list.

PLease Help

Regards

john
 
hi John,
Stefan
Than for the reply. However I am having difficulty with this code.
How do I use it?
I need to click the command button and select an email address from the
list.

Private Sub B_SelectEmail_Click()

Dim rs As DAO.Recordset
Dim Count As Integer

Set rs = SF_Email.Form.RecordsetClone
rs.MoveLast
rs.MoveFirst

If rs.RecordCount > 0 Then
rs.Move Int(rs.RecordCount * Rnd)
MsgBox rs![ID] & " - " & rs![Address]
Else
MsgBox "No address."
End If

End Sub

Take a look at the rounding with Int(), i'm not sure if it maps to all
recordsets.


mfG
--> stefan <--
 
Back
Top