Random Record Selection

Results 1 to 2 of 2

Thread: Random Record Selection

  1. #1
    Join Date
    Dec 1969

    Default Random Record Selection

    I’m trying to modify a simple Database application in order to retrieve Records in a Random order. Basically the application consists of a Table of Accounts and a simple Front End Form used to retrieve and update each account.<BR><BR>At present when the user clicks the “Next Account” command button the first available account is retrieved and displayed. The selection criteria states that the “Date_Actioned” field must be null, using the following code:<BR><BR> Private Sub Next_Account()<BR><BR>Dim db As Database<BR>Dim rst1 As Recordset<BR><BR>Dim sSearch As String<BR><BR>Set db = CurrentDB<BR><BR>sSearch = "SELECT TOP 1 * FROM tblAccounts "<BR>sSearch = sSearch & "WHERE tblAccounts.Date_Actioned Is Null "<BR> <BR>Set rst1 = db.OpenRecordset(sSearch, dbOpenDynaset, dbPessimistic)<BR><BR>If rst1.RecordCount &#060; 1 Then<BR> MsgBox "Sorry, there are no more records to work.", vbInformation, "Account Viewer"<BR> Exit Sub<BR>Else<BR> Display record details, edit & update etc… <BR><BR><BR>Question: How can I modify the SQL Statement to Select the next available account in Random order. For example, say I have 10 Accounts in my Table the first 5 of which have been previously updated (Date Field populated). When I click “Next Account” instead of being presented with Account 6, I wish to select a Random Account from the available records (i.e. 6-10). Is it possible to use the RecordCount property of the recordset as the upper limit in a random function?<BR>

  2. #2
    Join Date
    Dec 1969

    Default This seems strange...

    If there are 143 records that meet the SQL condition, are you still going to limit which record you display to just the range of records 6 through 10???<BR><BR>

Posting Permissions

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