call master form method (to requery subform2) from subform1

E

elburze

I have [master form], [subform1], and [subform2]
I want [subform2] to refresh after BarcodeID in [subform1] is updated.
In [subform1] for BarcodeID control I have:

Private Sub BarcodeID_AfterUpdate() 'in subform1
'Me.Parent.subform2.Requery
'Forms!subform2.Requery
'Me.Parent.requerySubform2 'calls a public sub in [master form]
End Sub

Public Sub requerySubform2() 'in [master form]
subform2.Requery
End Sub

but none of the commented out instructions work. Not even when calling
requerySubform2 (which works in master form, but does not work when called
from subform1!

So; my question is how to requery [subform2] from [subform1]?
or how to call procedures of [master form] or [subform2] from [subform1]?
 
S

Surendran

Hi,

You have to use the Form property of the subForm control.

Try this.
me.subform2.Form.Requery

When you call requery method of subform control, it requeries the data
source of the control.

Since the control is subForm, the data source is a Form which is given in
the properties sheet of subForm control in Source Object property.

Say your source sub form is "frmSubForm2".

So your code simply requeries to the source "frmSubForm2" but not to the
data source of "frmSubForm2" usually a query , table or SQL statement.


What is required is requerying the underlying data source of "frmSubForm2".

For this, you have to use the Form property of subForm control.

You can even change the source object programatically in VBA code.

Surendran
 
E

elburze

record source for [subform2] was another query. The problem was actually a
mistake that I make in access quite often! because it is tricky; I had to
save the form before I requeried another form!
You think the record saves automatically and you can just requery from the
updated data. And it is saved, but saved after the AfterUpdate() finishes!!!
Just thinking about the name of the function [AfterUpdate()] and checking
that in fact data has been saved makes you think now whatever you write in
AfterUpdate() (=AfterSave! or really? not!!! :( ) works on the new data.
Well, trick is Access calls the AfterUpdate() first, and then immidiately
updates the data!

So; AfterUpdate() is really RightBeofreUpdateRecordSource()! . After
Updates what? I guess after updating local value on the form's control, not
in the record source (table).
It was definitely confusing though. In Access you never know the exact order
and timing of events and updating of data until you learn it by experience.
That would be a hugh waste of time. Order of events might be in the help file
(maybe), but there should be more links to it when people search for controls
or events.
Meaning and order of events are not clear either. I mean just by reading
about AfterUpdate, OnCHange, OnExit, OnLostFocus I do not know which event
happens first, and what happens in between.
 
S

Surendran

Hi Elburze,
It was definitely confusing though. In Access you never know the exact order
and timing of events and updating of data until you learn it by experience.
That would be a hugh waste of time. Order of events might be in the help file
(maybe), but there should be more links to it when people search for controls
or events.
Meaning and order of events are not clear either. I mean just by reading
about AfterUpdate, OnCHange, OnExit, OnLostFocus I do not know which event
happens first, and what happens in between.

I suggest you to read a standard book like "Access 2000(or2002) Developer's
Handbook - Volume 1 by Ken Getz, ..." where in a full chapter "Chapter 2 -
The Access Event model" is devoted for Access events and there is a sample
form to test for a hands on practice and know the exact sequence of events
for various scenarios.

If you practice the sample form, then I hope you would definitely change
your mind against what you have now in your mind about Access Events.

Surendran

elburze said:
record source for [subform2] was another query. The problem was actually a
mistake that I make in access quite often! because it is tricky; I had to
save the form before I requeried another form!
You think the record saves automatically and you can just requery from the
updated data. And it is saved, but saved after the AfterUpdate() finishes!!!
Just thinking about the name of the function [AfterUpdate()] and checking
that in fact data has been saved makes you think now whatever you write in
AfterUpdate() (=AfterSave! or really? not!!! :( ) works on the new data.
Well, trick is Access calls the AfterUpdate() first, and then immidiately
updates the data!

So; AfterUpdate() is really RightBeofreUpdateRecordSource()! . After
Updates what? I guess after updating local value on the form's control, not
in the record source (table).
 
E

elburze

Ok, that is what I should look at. Thanks.

Surendran said:
Hi Elburze,
It was definitely confusing though. In Access you never know the exact order
and timing of events and updating of data until you learn it by experience.
That would be a hugh waste of time. Order of events might be in the help file
(maybe), but there should be more links to it when people search for controls
or events.
Meaning and order of events are not clear either. I mean just by reading
about AfterUpdate, OnCHange, OnExit, OnLostFocus I do not know which event
happens first, and what happens in between.

I suggest you to read a standard book like "Access 2000(or2002) Developer's
Handbook - Volume 1 by Ken Getz, ..." where in a full chapter "Chapter 2 -
The Access Event model" is devoted for Access events and there is a sample
form to test for a hands on practice and know the exact sequence of events
for various scenarios.

If you practice the sample form, then I hope you would definitely change
your mind against what you have now in your mind about Access Events.

Surendran

elburze said:
record source for [subform2] was another query. The problem was actually a
mistake that I make in access quite often! because it is tricky; I had to
save the form before I requeried another form!
You think the record saves automatically and you can just requery from the
updated data. And it is saved, but saved after the AfterUpdate() finishes!!!
Just thinking about the name of the function [AfterUpdate()] and checking
that in fact data has been saved makes you think now whatever you write in
AfterUpdate() (=AfterSave! or really? not!!! :( ) works on the new data.
Well, trick is Access calls the AfterUpdate() first, and then immidiately
updates the data!

So; AfterUpdate() is really RightBeofreUpdateRecordSource()! . After
Updates what? I guess after updating local value on the form's control, not
in the record source (table).
 
M

Marshall Barton

elburze said:
record source for [subform2] was another query. The problem was actually a
mistake that I make in access quite often! because it is tricky; I had to
save the form before I requeried another form!
You think the record saves automatically and you can just requery from the
updated data. And it is saved, but saved after the AfterUpdate() finishes!!!
Just thinking about the name of the function [AfterUpdate()] and checking
that in fact data has been saved makes you think now whatever you write in
AfterUpdate() (=AfterSave! or really? not!!! :( ) works on the new data.
Well, trick is Access calls the AfterUpdate() first, and then immidiately
updates the data!

So; AfterUpdate() is really RightBeofreUpdateRecordSource()! . After
Updates what? I guess after updating local value on the form's control, not
in the record source (table).
It was definitely confusing though. In Access you never know the exact order
and timing of events and updating of data until you learn it by experience.
That would be a hugh waste of time. Order of events might be in the help file
(maybe), but there should be more links to it when people search for controls
or events.
Meaning and order of events are not clear either. I mean just by reading
about AfterUpdate, OnCHange, OnExit, OnLostFocus I do not know which event
happens first, and what happens in between.


Surendran's recommended reading is definitely called for
here since your basic premiss is flawed. The AfterUpdate
event serves different purposes depending on the object that
is being updated.

A **control's** AfterUpdate event occurs **after** the
control's Value property has been set. Editing a control
goes through several steps and the AfterUpdate event signals
that the editing process has been completed. Note that
nothing is saved to a table at this point.

The **form's** AfterUpdate event occurs **after** changes to
the current record have been saved to the table.
 

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