Computing.Net > Forums > Programming > VB Code For Random

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB Code For Random

Reply to Message Icon

Name: JHargett
Date: February 20, 2008 at 08:45:37 Pacific
OS: Windows
CPU/Ram: XP Ram 512
Product: Access 2002
Comment:

I have tried this code and find that each time I open the program it starts down the same line (Item A is always first then item 5, etc.)
Could anyon help me put it so that I never know who comes next fully random?
Function FindRandom(Random As String, Field As String)

Dim MyDB As Database
Dim MyRS As Recordset
Dim SpecificRecord As Long, i As Long, NumOfRecords As Long

Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset(Random, dbOpenDynaset)
MyRS.MoveLast
NumOfRecords = MyRS.RecordCount
SpecificRecord = Int(NumOfRecords * Rnd)
If SpecificRecord = NumOfRecords Then
SpecificRecord = SpecificRecord - 10
End If
MyRS.MoveFirst
For i = 1 To SpecificRecord
MyRS.MoveNext
Next i
FindRandom = MyRS(ID)
Exit Function

No Records:
If Err = 3021 Then
MsgBox "There Are No Records In The Dynset", 16, "Error"
Else
MsgBox "Error - " & Err & Chr$(13) & Chr(10) & Error, _
16, "Error"
End If
FindRandom = "No Records"
Exit Function

End Function


James



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: February 20, 2008 at 18:21:48 Pacific
Reply:

At the start of the program, insert a

Randomize Timer


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB Code For Random

A VB Code for Printed pages counter www.computing.net/answers/programming/a-vb-code-for-printed-pages-counter/12702.html

audio spectrum analyser in vb code www.computing.net/answers/programming/audio-spectrum-analyser-in-vb-code/8179.html

VB Code To Disable CD Drive www.computing.net/answers/programming/vb-code-to-disable-cd-drive/11665.html