Results 1 to 4 of 4

Thread: Random record

  1. #1
    Join Date
    Nov 2004
    Posts
    3

    Unanswered: Random record

    Hi,

    I am wanting to return a random record from a field in a table to a form so that each time the form is opened it shows a different record, I know I can do a qry where the user enters a record ID number but I was try to avoid that step.

    If anyone has any suggestions I'll be all ears

    Cheers

  2. #2
    Join Date
    Sep 2003
    Posts
    228
    Dim objRandom As New System.Random( _
    CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))

    Code:
    Public Function GetRandomNumber( _
      Optional ByVal Low As Integer = 1, _
      Optional ByVal High As Integer = 100) As Integer
      ' Returns a random number,
      ' between the optional Low and High parameters
      Return objRandom.Next(Low, High + 1)
    End Function
    usage:
    Code:
    Dim intDiceRoll As Integer
    intDiceRoll = GetRandomNumber(1, 6)
    MessageBox.Show("You rolled a " & intDiceRoll.ToString)
    Assuming your records are identified by a continuous set of numbers from 'low' to 'high'

  3. #3
    Join Date
    Sep 2003
    Posts
    228

  4. #4
    Join Date
    Nov 2004
    Posts
    3
    Many thanks Ottomatic
    I'll give it a try

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •