recordset property

T

Thanh-Nhan Le

Hi,
I have 2 forms, which displays the same datasource.
I want to synchronize 2 forms.

in formload of Form1, I use:
set form2.recordset = me.recordset
that is OK, when I move to another record, the two Forms are show the same
record.

But when I change the filter of Form1, Form2 is not filtered automatically.
And when I use again the recordset property (after filter):
set form2.recordset = me.recordset
then
the filter of Form1 had no effect (no filter).

Or When I set the Filter of 2 Forms separately, then they are not
synchronized together:
me.filter = "..."
me.filteron = true
form2.filter = "..."
form2.filteron = true

Why? What can I do?

Thanks for help
Nhan
 
M

Marshall Barton

Thanh-Nhan Le said:
I have 2 forms, which displays the same datasource.
I want to synchronize 2 forms.

in formload of Form1, I use:
set form2.recordset = me.recordset
that is OK, when I move to another record, the two Forms are show the same
record.

But when I change the filter of Form1, Form2 is not filtered automatically.
And when I use again the recordset property (after filter):
set form2.recordset = me.recordset
then
the filter of Form1 had no effect (no filter).

Or When I set the Filter of 2 Forms separately, then they are not
synchronized together:
me.filter = "..."
me.filteron = true
form2.filter = "..."
form2.filteron = true


Inferring from how the recordset's Filter property works, I
think form1 has a different recordset object when you apply
a filter. When testing appeared to confirm that hypothesis,
I conclude that the form1 code you need is more like:
me.filter = "..."
me.filteron = true
set form2.recordset = me.recordset

If you don't reset the other form's recordset, the two forms
will have different recordsets and can not remain
synchronized.

I must say that I am more than a little uncomfortable with
all this recordset flip-flopping. Seems like a lot of
objects are just left hanging and I have no idea what, if
any, negative consequences might be invoked by all this.
Try changing the filter on either form 50+ times to see if
anything blows up :-|

If things go south, try making form2 change form1's filter
and always setting form2's recordset to form1's recordset.

In spite of being called old fashioned, you could always
fall back to the old standby approach of constructing the
record source SQL statement to filter the data. Set both
forms to the same SQL statement and use FindFirst in each
forms' Current event to navigate to the same record in the
other form.
 
T

Thanh-Nhan Le

OK,
I though so.
My 2 Forms are Subforms on a main form, one for datasheet, one for formview.
After set the filter of the 1. Form:
form1.form.filter = "..."
form1.form.filterOn = true

I reset the recordset of form2:
set form2.form.recordset = form1.form.recordset

but there is here a problem, as I wrote: the form1 is not filtered anymore
(after this code). Why.

I though, both form use the same recordset (as pointer on a recordset
object), any change (inclusiv Filter) will occur on both form recordset.
When we write code for the synchron. self, it is much work, complex, why I
must to know, when the users channge the filter (they can do it over
toolbar, contextmenu...).

OK, but that can be an error of Access.

Thanks
 
M

Marshall Barton

Thanh-Nhan Le said:
I though so.
My 2 Forms are Subforms on a main form, one for datasheet, one for formview.
After set the filter of the 1. Form:
form1.form.filter = "..."
form1.form.filterOn = true

I reset the recordset of form2:
set form2.form.recordset = form1.form.recordset

but there is here a problem, as I wrote: the form1 is not filtered anymore
(after this code). Why.

I though, both form use the same recordset (as pointer on a recordset
object), any change (inclusiv Filter) will occur on both form recordset.
When we write code for the synchron. self, it is much work, complex, why I
must to know, when the users channge the filter (they can do it over
toolbar, contextmenu...).

Sheesh, two subforms, one in form view. Why didn't you say
so ;-)

One of the known problems with the Filter property is that
setting it for the main form or any subform, clears it on
all the others (which is only one of the reasons I never use
it).

Regardless, of all that, the easiest way to synchronize two
subforms is to add a hidden text box (named txtLink) to the
main form's header (or footer) section. Use the continuous
or datasheet subform's Current event to set the text box to
the current record's primary key value:
Parent.txtLink = Me.pkfield

With that in place, set the form view subform control's Link
Master Fields property to txtLink and its Link Child Fields
property to pkfield.

Done! No need for all that other fooling around, just the
one line of code.
 

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