Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Report with random numbers

Status
Not open for further replies.

Hew

MIS
Apr 6, 2000
3
US
I am creating an Access report from one table.  One of the fields is a numeric value.    It is the file number that ranges from 1 to 4300.  I want to show a random sample of 56 of these in the report. Please help me.
 
I would use the RND function to get records and add them to a table.<br>Then base your report on that table<br><br>--------------- Here is a simple one example that generates numbers ---------------<br>Public Sub RandomNums()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim db As Database, rst, rst2 As Recordset, SQL As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Set db = CurrentDb<br>&nbsp;&nbsp;&nbsp;&nbsp;' SQL string.<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rst2 = db.OpenRecordset(&quot;RndNumbers&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;For a = 1 To 25<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL = &quot;SELECT * FROM number1 WHERE numbers = &quot; & Int((50 * Rnd) + 1) & &quot;;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set rst = db.OpenRecordset(SQL)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst2.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst2!RndNumber = rst!Numbers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst2.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;Next<br>&nbsp;&nbsp;&nbsp;&nbsp;rst2.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;rst.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;db.Close<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br>------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top