By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

RecordSet as Record Source

P: n/a
Lyn
If I have a form where the RecordSource property is set to the name of a
table, then on opening the SingleForm form I can cycle through all the
records in the table one at a time via Next and Previous buttons on the
form.

However, I only want to cycle through a subset of the table. I have a
parent form which inputs selection criteria. With the selection criteria I
create a RecordSet (using ADO) in the parent form. The RecordSet object is
declared as Public, so it should be accessible in all modules.

I feel that when loading the main form from the parent form, I should be
able to set its RecordSource property to the Public RecordSet so that the
form sees only the selected subset of records. I do this through the Load
event.

But when I do this, I get an error message that the RecordSet is not
recognised as valid Record Source. The recordset remains open in the parent
form until the form is closed or another set of criteria is input.

What am I doing wrong? Is it not valid to have a recordset as the Record
Source in a form? Or am I not declaring the recordset object correctly such
that it is not recognised across modules? Is there a better way to achieve
this anyway?

--
Cheers,
Lyn.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Coupla things here.
First, RecordSource is a string property which gives the name of the table
or query on which the form's data is based, so you can't set a string
property to a recordset.
Second, if you're using Access 2000 or later, forms have a Recordset
property you can set, which will probably do what you want.
Third, I'd suggest using the form's Open event, rather than Load, because
Load doesn't fire until after the pre-defined recordset is loaded, so it
would have to re-load the data. By using Open, you can change the recordset
before it's loaded.
Fourth, if you're just limiting the data in the form, you can build a
criteria string in the code on the main form and pass that as an argument of
DoCmd.OpenForm. No need to build an extra recordset.

HTH

"Lyn" <lh******@ihug.com.au> wrote in message
news:cs**********@lust.ihug.co.nz...
If I have a form where the RecordSource property is set to the name of a
table, then on opening the SingleForm form I can cycle through all the
records in the table one at a time via Next and Previous buttons on the
form.

However, I only want to cycle through a subset of the table. I have a
parent form which inputs selection criteria. With the selection criteria I create a RecordSet (using ADO) in the parent form. The RecordSet object is declared as Public, so it should be accessible in all modules.

I feel that when loading the main form from the parent form, I should be
able to set its RecordSource property to the Public RecordSet so that the
form sees only the selected subset of records. I do this through the Load
event.

But when I do this, I get an error message that the RecordSet is not
recognised as valid Record Source. The recordset remains open in the parent form until the form is closed or another set of criteria is input.

What am I doing wrong? Is it not valid to have a recordset as the Record
Source in a form? Or am I not declaring the recordset object correctly such that it is not recognised across modules? Is there a better way to achieve this anyway?

--
Cheers,
Lyn.

Nov 13 '05 #2

P: n/a
Lyn
Thanks for the quick response. I should have mentioned that I am using
Access 2003, but I was unaware of the RecordSet property -- I am looking
into that now. And I will try doing this in Open and see how it goes.

I was passing the name of the recordset as a string to the Record Source
property.

And actually, I am doing quite a bit more in the parent form. I already
have the recordset created and I was looking for a way to avoid having to
create it again in the other form.

Anyway, I will study your advice and see how I go.

Thanks again.

--
Cheers,
Lyn.

"MacDermott" <ma********@nospam.com> wrote in message
news:LW*****************@newsread3.news.atl.earthl ink.net...
Coupla things here.
First, RecordSource is a string property which gives the name of the table
or query on which the form's data is based, so you can't set a string
property to a recordset.
Second, if you're using Access 2000 or later, forms have a Recordset
property you can set, which will probably do what you want.
Third, I'd suggest using the form's Open event, rather than Load, because
Load doesn't fire until after the pre-defined recordset is loaded, so it
would have to re-load the data. By using Open, you can change the
recordset
before it's loaded.
Fourth, if you're just limiting the data in the form, you can build a
criteria string in the code on the main form and pass that as an argument
of
DoCmd.OpenForm. No need to build an extra recordset.

HTH

"Lyn" <lh******@ihug.com.au> wrote in message
news:cs**********@lust.ihug.co.nz...
If I have a form where the RecordSource property is set to the name of a
table, then on opening the SingleForm form I can cycle through all the
records in the table one at a time via Next and Previous buttons on the
form.

However, I only want to cycle through a subset of the table. I have a
parent form which inputs selection criteria. With the selection criteria

I
create a RecordSet (using ADO) in the parent form. The RecordSet object

is
declared as Public, so it should be accessible in all modules.

I feel that when loading the main form from the parent form, I should be
able to set its RecordSource property to the Public RecordSet so that the
form sees only the selected subset of records. I do this through the
Load
event.

But when I do this, I get an error message that the RecordSet is not
recognised as valid Record Source. The recordset remains open in the

parent
form until the form is closed or another set of criteria is input.

What am I doing wrong? Is it not valid to have a recordset as the Record
Source in a form? Or am I not declaring the recordset object correctly

such
that it is not recognised across modules? Is there a better way to

achieve
this anyway?

--
Cheers,
Lyn.


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.