Finding number of records in a table

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I need to have a form randomly display test questions from
a table. In order to do this, the code needs to first
know how many records are in the table. I have tried to
figure out how to use "recordcount" and have had no luck.
Ultimately, I'd like to use the following lines to go to a
random record:

MyValue = Int((varnumber * Rnd) + 1)
DoCmd.GoToRecord , , acGoTo, MyValue

where varnumber = the number of records.

Can anyone give me a fairly exact example of how to get
the number of records in my table and store the result in
the variable varnumber?

Is there an easier way to have a random record selected
each time a button is pushed?

At some point I may use queries to limit the types of
questions to be used for each particular test and then I
will need to count the results of the query, not the
entire table, but I will worry about that later.

Thanks for your help!!!!

Rick
 
Rick said:
I need to have a form randomly display test questions from
a table. In order to do this, the code needs to first
know how many records are in the table. I have tried to
figure out how to use "recordcount" and have had no luck.
Ultimately, I'd like to use the following lines to go to a
random record:

MyValue = Int((varnumber * Rnd) + 1)
DoCmd.GoToRecord , , acGoTo, MyValue

where varnumber = the number of records.

Can anyone give me a fairly exact example of how to get
the number of records in my table and store the result in
the variable varnumber?

varnumber = DCount("*", "YourTableName")
 
Can anyone give me a fairly exact example of how to get
the number of records in my table and store the result in
the variable varnumber?

Here is how you can determine the number of records currently in the form's
recordset (whether based on a table or a query):

'***EXAMPLE START
'When # records will be large, you might need to use a "Long"
' rather than an Integer
Dim intRecCount As Integer
'Get the count
With Me.RecordsetClone
.MoveLast 'This is necessary to get accurate count
intRecCount = .RecordCount
End With
'***'***EXAMPLE END
 
Back
Top