|
-
Apr 5th, 2001, 10:22 AM
#1
Thread Starter
New Member
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
-
Apr 5th, 2001, 11:01 AM
#2
Addicted Member
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!
-
Apr 5th, 2001, 11:29 AM
#3
Retired VBF Adm1nistrator
Personally I'd hard-code the tips into an array ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 5th, 2001, 12:33 PM
#4
Thread Starter
New Member
Working, but first recordset never changes!
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
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
|