Refresh subform

  • Thread starter Thread starter Sammy
  • Start date Start date
S

Sammy

I have a form based on a table. The form has a subform
based on a query. After I enter information in the form,
the subform remains blank. If I leave the record and
come back, the subform populates properly. I want to put
a button on the form to populate the subform without
leaving the record. What command do I use? I've tried
DoCmd.save & DoCmd.requery to no avail. Thanks.
 
try

Me!NameOfSubformControl(not the name of the subform itself).Requery

you can use that with a command button, or use it with the main form's
AfterUpdate event for automatic updating.

hth
 
It's not working. I'm not sure I am picking up the name
of the subform control correctly. I have:
Subform name: ShipEstimateSfm
Source object of subform: ShipEstimateSfm (happens to be
the same as subform name)
Record source of subform: RateCalculator (query)
I tried
Me!ShipEstimateSfm.Requery (compiles ok, but doesn't work)
also
Me!ShipEstimateSfm!RateCalculator.Requery (errors)
No Joy.
 
ok, try

Me!ShipEstimateSfm.Form.Requery

probably should have said that in the first place, sorry.
 
That didn't work either. Could it have something to do
with relationships? The table is not related to the
query. However, the subform works the way I want it to,
so it still seems to me that I ought to be able to have
the subform behave the same way it does when it moves to
a different record. Whoa! frustrating little thing!
 
Is the query in the subform using a value from a control on the main form as
a criterion when it runs?

On which event are you trying to use this Requery? It should be on the
control's AfterUpdate event (or, as Tina said, the form's AfterUpdate event
if you're moving to another record or save the record -- however, it may be
that your form's design is not causing the form's AfterUpdate event to occur
when you want to have the subform requeried, so use the control's
AfterUpdate event).
 
Answer to question 1: yes, it's using two values. It's a
look-up to the rate field in the subform based on the
fields "weight" and "country", which are found on both
the form and the subform.
Question 2: which control's AfterUpdate event? It
doesn't work on either the form's AfterUpdate event or
the last field in the form's AfterUpdate event. Doesn't
the AfterUpdate event fire only when you leave the
record?
I have a work-around. I set up a command button to move
to the previous record and immediately to the next
record. It works, but is it a bad idea for some reason
which I can't anticipate?
Thanks.
 
well, since you're going the command button route: instead of moving back
then forward in the records, suggest you try the following code on your
command button, as

DoCmd.RunCommand acCmdSaveRecord
Me!ShipEstimateSfm.Form.Requery

doublecheck the name of your subform *control*. in mainform design view, *do
not* click on the subform to select it. instead, right-click on it and
select Properties from the shortcut menu. the title bar of the Properties
box should say Subform/Subreport. click on the Other tab and look at the
Name property. use the correct name in the line of code above.

hth
 
Thanks everybody for your help. This worked!
-----Original Message-----
well, since you're going the command button route: instead of moving back
then forward in the records, suggest you try the following code on your
command button, as

DoCmd.RunCommand acCmdSaveRecord
Me!ShipEstimateSfm.Form.Requery

doublecheck the name of your subform *control*. in mainform design view, *do
not* click on the subform to select it. instead, right- click on it and
select Properties from the shortcut menu. the title bar of the Properties
box should say Subform/Subreport. click on the Other tab and look at the
Name property. use the correct name in the line of code above.

hth





.
 
A control's AfterUpdate event occurs after you've entered a new/changed
value into the control and no errors have occurred. You do not need to leave
the control nor leave the record.
 
Back
Top