Filtering Records for a Form

F

Frank Wagner

I develop Math Software for Elementarty Schools using Access 2000.

I am using the following statement to open up various testing forms and go
to a random record that was selected for testing purposes.
"DoCmd.GoToRecord acDataForm, "FormName", acGoTo, intRandomRecordNo".

Is there any way I can only show the selected record by filtering the data
using a similar statement?

Any help would be appreciated.
 
G

Graham Mandeno

Hi Frank

Base your form's RecordSource on a query like this:

Select top 1 * from YourTable order by Rnd(Abs([SomeNumericField]))

....where SomeNumericField is a field in your table guaranteed to contain
numeric data (an AutoNumber is ideal).

Then your recordset will return only one random record.
 
F

Frank Wagner

Graham:

I use the test module to call questions from over 30 different forms. In
addition, the forms are used for numerous applications other than testing.
I'd like to avoid changing the record source for all the forms if I possibly
can. Is there any way I can accomplish the task by merely adjusting the
statement I use to open the form so it just opens one relative record number
according a random number that I have already created?

Your help is appreciated.
--
Frank Wagner
(e-mail address removed)


Graham Mandeno said:
Hi Frank

Base your form's RecordSource on a query like this:

Select top 1 * from YourTable order by Rnd(Abs([SomeNumericField]))

....where SomeNumericField is a field in your table guaranteed to contain
numeric data (an AutoNumber is ideal).

Then your recordset will return only one random record.
 
G

Graham Mandeno

Hi Frank

You could say:
Me.Filter = "[PrimaryKeyField]=" & Me.[PrimaryKeyField]
Me.FilterOn = True

That will apply a filter that limits the recordset to the record currently
being displayed.

As a matter of interest, how do you calculate intRandomRecordNo?

Is it:
intRandomRecordNo = Int(Me.RecordsetClone.RecordCount * Rnd)
?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Frank Wagner said:
Graham:

I use the test module to call questions from over 30 different forms. In
addition, the forms are used for numerous applications other than testing.
I'd like to avoid changing the record source for all the forms if I
possibly
can. Is there any way I can accomplish the task by merely adjusting the
statement I use to open the form so it just opens one relative record
number
according a random number that I have already created?

Your help is appreciated.
--
Frank Wagner
(e-mail address removed)


Graham Mandeno said:
Hi Frank

Base your form's RecordSource on a query like this:

Select top 1 * from YourTable order by Rnd(Abs([SomeNumericField]))

....where SomeNumericField is a field in your table guaranteed to contain
numeric data (an AutoNumber is ideal).

Then your recordset will return only one random record.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Frank Wagner said:
I develop Math Software for Elementarty Schools using Access 2000.

I am using the following statement to open up various testing forms and
go
to a random record that was selected for testing purposes.
"DoCmd.GoToRecord acDataForm, "FormName", acGoTo, intRandomRecordNo".

Is there any way I can only show the selected record by filtering the
data
using a similar statement?

Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top