Hi there,
I'm currently using Data Control. I'm trying to open a screen showing random 'Tips of the Day'. And i don't know the code to select a Random recordsets in my Access database.
Please Help!
cheers
Claire
Printable View
Hi there,
I'm currently using Data Control. I'm trying to open a screen showing random 'Tips of the Day'. And i don't know the code to select a Random recordsets in my Access database.
Please Help!
cheers
Claire
If all your 'Tips...' are in the same recordset and you want pick a random one, try using a random number generator in conjuction with the Move method of the recordset attached to your datacontrol....ie.
Datacontrol.Recordset.Move Int((100 - 1) * rnd + 1)
Note: The number 100 is the upper limit of you random # range, the number 1 is the lower limit.
Hope this works for you!
Personally I'd hard-code the tips into an array ...
I've got the random code to work but each time i execute it, it opens with the same Recordset!......Any suggestions on how i can get around this??
And when i close the form and then go to view it again,....no Tips (Recordsets) are shown!! Any ideas?
Private Sub Command1_Click()
Dim Id As Integer
Dim tip As String
Id = Int(22 * Rnd) + 1
Data1.Recordset.FindFirst "Tip_id = " & Id & ""
tip = Data1.Recordset.Fields(1)
Label1.Caption = tip
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Initialize()
Dim Id As Integer
Dim tip As String
Id = Int(22 * Rnd) + 1
Data1.Recordset.FindFirst "Tip_id = " & Id & ""
tip = Data1.Recordset.Fields(1)
Label1.Caption = tip
End Sub