random number generator to get an item from access
hi Everyone,
I am trying to write a programme for a membership draw. I have created a membership database with 360 members.
What I want to do is get VB to pick a random number from 1 to 360, then go to the database and then display what the field is located at that number.
I have created the database so that there is a "number Record" as the key.
ie if VB selects 60, I want VB to show what information is at record number 60.
I have looked through the forums for an answer, but cant quite find what I am looking for.
Hope someone can help
Re: random number generator to get an item from access
Re: random number generator to get an item from access
what is your database structure?
Re: random number generator to get an item from access
Database structure is:
Field 1 - Number
Field 2 - Surname
Field 3 - Given Name
All I need it to do is randomly select a number, then display first and given name
Re: random number generator to get an item from access
Heres how to get a random between two values:
VB Code:
Private Sub Command1_Click()
'get a random with 5 being the low, 10 being the high boundry
MsgBox GetRandom(5, 10)
End Sub
Private Sub Form_Load()
' randomize to ensure it is random and
' not the same sequence each time it runs
Randomize
End Sub
Public Function GetRandom(ByVal Low As Long, ByVal High As Long) As Long
'This function takes a low and high and returns a random between them
GetRandom = CLng((High - Low + 1) * Rnd + Low)
End Function
@cssriraman that function you posted returns a variant and tries to emulate a simple loop by using Goto labels!