How do I refresh/requery a subform

  • Thread starter Thread starter acs68
  • Start date Start date
A

acs68

Hi all,

I have a form that updates some records in a table. The subform that refers
to this data does not change when I update the underlying table. If I go out
of the form and back in, the data is there.

How can I refresh/requery the subform to display the data immeditaely after
the update is completed ?

cheers,

Adam
 
How can I refresh/requery the subform to display the data immeditaely after
the update is completed ?

With a single line of code:

Forms!mainformname!subformcontrol.Requery

where subformcontrol is the name of the Subform control on the main
form (not necessarily the same as the name of the form within that
control).
 
How would you write the code if the "mainform" being
referred to is actually a subform of another mainform?

e.g. the subcontrol is on a subform of a subform.

When I enter the code, it says that the form does not
exist (but if I do it without the higher level form, it
works fine!)
 
How does one have to amend this code to work on a
subform? e.g. the subform is requeried from the form
(which is a subform itself)?

Help!
 
How does one have to amend this code to work on a
subform? e.g. the subform is requeried from the form
(which is a subform itself)?

Two ways:

Me.subformcontrol.Requery ' if the code is on the first level sub
Forms!mainform!firstsubform.Form!secondsubform.Requery ' if not
 
I am not sure if I understood your reply...sorry.

So, if the field to be updated is on the first subform but
I want it to update when I move to the second subform;
then I type (in the Enter event for the second subform):

Me.subformcontrol.Requery
Forms!mainform!firstsubform.Form!secondsubform.requery

Is that correct? That is what I did and it did not seem
to work.

Sorry for my ignorance here.

Al
 
I am not sure if I understood your reply...sorry.

So, if the field to be updated is on the first subform but
I want it to update when I move to the second subform;
then I type (in the Enter event for the second subform):

Me.subformcontrol.Requery
Forms!mainform!firstsubform.Form!secondsubform.requery

Is that correct? That is what I did and it did not seem
to work.

Sorry for my ignorance here.

I think it's my misreading of your post!

Let's get concrete. Say you have a form name MyForm; on it is a
Subform control named sbfrmOne, which contains a form named frmOne. On
frmOne there is a subform control named sbfrmTwo, containing a form
named frmTwo.

If I understand you, when you set focus to any control in frmTwo, you
want to Requery a field (control?) on frmOne? Why? The data in frmOne
is written to disk immediately on setting focus to frmTwo; changing a
value on the form may not even be possible.

Please explain what you're trying to accomplish!
 
Here is what I am trying to accomplish:

Form 1
Form 2 (subform of Form 2)
Form 3 (subform of Form 3)This form has multiple records
showing in datasheet view.

(I am not using subform controls, the subforms are just
sitting in the main form, so no click is necessary).

There is a field on Form 2 which is an autonumber - lets
call it client#. (The tables are in SQL Server so the
autonumber field does not have a value in it until the
record is closed).

Form 3 has the client# field in it - so that it relates to
Form 2. I have code which requeries Form 2 when Form 3
opens, then I need to have the client# automatically fill
in to all records in Form 3.


I have entered code:

Private Sub Form3_Enter()
Me.client#.Requery
Forms!Form1!Form2!Form3!client# = Forms!Form1!Form2!client#
End Sub

This works up to a point. The client# only shows up in
the first record of Form3, not in any of the other records
showing.

Can you help?
 
Here is what I am trying to accomplish:

Form 1
Form 2 (subform of Form 2)
Form 3 (subform of Form 3)This form has multiple records
showing in datasheet view.

(I am not using subform controls, the subforms are just
sitting in the main form, so no click is necessary).

Oh. "I'm not using subform controls, the subforms are..."

Then THEY ARE NOT SUBFORMS. I was assuming that when you said that you
were using a subform that you were in fact using a subform. My code
applies to Subforms, which is what you were asking about (or so I
thought).

So are you using a popup form, with code to open it or set focus to it
or what?
There is a field on Form 2 which is an autonumber - lets
call it client#. (The tables are in SQL Server so the
autonumber field does not have a value in it until the
record is closed).

Form 3 has the client# field in it - so that it relates to
Form 2. I have code which requeries Form 2 when Form 3
opens, then I need to have the client# automatically fill
in to all records in Form 3.


I have entered code:

Private Sub Form3_Enter()
Me.client#.Requery
Forms!Form1!Form2!Form3!client# = Forms!Form1!Form2!client#
End Sub

This works up to a point.

This should not work AT ALL, unless you're confusing me even more;
this syntax applies to Subforms on Subform controls - which you say
you are not using.
The client# only shows up in
the first record of Form3, not in any of the other records
showing.

Of course it does; a form (or subform) has only one active record, and
if you have not selected a record, that will be the first record.

You're doing this in a VERY strange way - filling Form3, and only
afterward filling in the Client#?

Just FWIW, if you're not in fact already doing so, I'd suggest using
Subform Controls with these subforms in them; and including Client# as
the Master/Child Link Field of the subform control containing Form3.
This will cause Form2 to be saved to disk (automatically, with no code
needed) when you setfocus to Form3, and will fill in the Client#
automatically - again, no code needed.
 
Back
Top